2014-04-14 2 views
0

나는 편지함 보석을 사용하여 내 레일 앱을 사용자가 마사지하는 작업을했습니다.편지함을 사용하여 게시물 사용자에게 회신하는 방법

어떤 이유로 메시지 양식을 렌더링 할 수없고 user.id와 같은 값이 전달되지 않습니다. 어떻게해야합니까? 내가 가까이있어 알고 있지만 내가보기/글/show.html.erb이 하나 와 함께 하드 코어를 만지는 해요 : 나는 새 메시지 경로를 클릭하면

<strong>title & author</strong> 
<h2><%= @post.title %></h2> 

    <p><%= @post.author %></p> 
</div> 

<strong>course</strong><br /> 
<h1><%= @post.course %></h1> 



<strong>school</strong><br /> 
<h1><%= @post.school %></h1> 


<strong>price</strong><br /> 
<h1><%= @post.price %></h1> 

<p> 
    <strong>Posted by</strong><br /> 
    <%= @post.email %> 
    </p> 
    <br /> 
    <h2>Description</h2> 
    <h1><%= word_wrap(@post.description, :line_width => 8) %></h1> 


    <br /> 
    DATE POSTED: <%= @post.created_at %><br /><br /> 


    </div> 

    <%= link_to "reply", new_message_path %> 
<!--%= render 'messages/form', conversation: conversation % --> 

이 페이지가가 간다 : 보기/메시지/new.html.erb

Send a message to 

<%= @user.username %> 
<%= form_tag({controller: "messages", action: "create"}, method: :post) do %> 
<%= label_tag :subject %> 
<%= text_field_tag :subject %> 
<%= label :body, "Message text" %> 
<%= text_area_tag :body %> 
<%= hidden_field_tag(:user, "#{@user.id}") %> 
<%= submit_tag 'Send message' %> 
<% end %> 

나는 게시물의 사용자 이름의 값을 전달하거나 메시지 양식에 post.email를 전달하고 싶습니다.

나는 그것을 시도 다른 방법, 나는 그 일의 선호하는 방법은 '메시지/양식을', 렌더링 = <퍼센트이다 대화 : 대화 %> 하지만 난 얻을 수행 할 때

undefined method error for 'conversation' 

보기/메시지/_form.html.erb :

Reply: 
<%= form_for :message, url: [:reply, conversation] do |f| %> 
<%= f.text_area :body %> 
<%= f.submit "Send Message", class: 'btn btn-primary' %> 
<%= submit_tag 'Clear Reply Box', type: :reset, class: 'btn btn-danger' %> 
<% end %> 

은 기본적으로 내가 게시물에 회신 버튼을 추가하고 사용자가 게시 한 사용자에게 메시지를 보낼 수 있도록합니다. 내가 고안 사용하고 있는데 모든 사용자에 기록됩니다.

답변

1

당신은 당신의 routes.rb에 게시물 아래에 중첩 새 메시지를 정의해야합니다 ...

resources :posts do 
    resources :messages, only: [:new, :create] 
    end 

당신에게 경로를 줄 것이다 new_post_message GET/게시물/: [: post_id를]를 먹어 치운다에 posts_id/메시지/새 메시지 # 당신은 PARAM의 통과 링크

<%= link_to 'reply', new_post_message_path(@post) %> 

의 일환으로 게시물을 지정합니다

를 만들 메시지 컨트롤러의 메소드를 사용하여 게시물을 검색하고, 인스턴스 변수로 설정하고,보기/메시지/새 형식으로 사용할 수 있습니다.

+0

댓글이 없습니다. 메시지입니다. – franklinexpress

+0

안녕하세요. 죄송합니다. 연상의 순간이었습니다. 답변이 수정되었습니다. 더 유용 할 것입니다. – SteveTurczyn

관련 문제