0
다른 사용자에게 메시지를 보내려고합니다. 그러나 필드를 비워두면 제어기가 또 다른 '새로운'동작을 렌더링합니다. 여기 양식에서 변수를 '새'작업으로 제출하는 방법
는에 연결하는 뷰 코드 첫 번째 제출 : 여기def new
@message = Message.new
@recipient = Profile.find(params[:recipient_id])
end
메시지 # 새로운 뷰 코드 : 여기
<%= link_to 'Send Mail', {:controller => 'messages', :action => 'new', :recipient_id => @profile.id}, :class => 'btn btn-large btn-primary' %>
메시지 # 새로운 코드
<%= simple_form_for @message do |f| %>
<%= f.input :title %>
<%= f.input :body %>
<%= f.input :recipient_id, :as => :hidden, :input_html => {:value => @recipient.id} %>
<%= f.input :sender_id, :as => :hidden, :input_html => {:value => @recipient.id} %>
<%= f.button :submit %>
<% end %>
다음은 메시지 # 작성 코드입니다.
def create
@message = Message.new(params[:message])
if @message.save
flash[:notice] = "New message created"
redirect_to @message
else
flash[:error] = "Did not work"
@recipient = params[:recipient_id]
render action: "new"
end
end
: recipient_id 값을 양식에 제출하고 새 동작 렌더링을 전달하려면 어떻게합니까? 당신이 그것을 코드가 실행되지 않습니다 new
방법 레일을 렌더링 할 때
그! 나는 원래의 쿼리 문자열 대 게시물 요청에서오고 있기 때문에 다른 params 값이 필요하다고 생각한다. 또한 @recipient가 이전과 같은 클래스가되어야합니다. – Castielle