2013-10-11 5 views
1

나는 메시징 기능을 위해 Mailboxer gem을 사용하고 있지만, 나는 아주 새 것이므로 사용법을 잘 모르고있다. 기본적으로 나는 다음과 같은 메시지가 컨트롤러를 생성 :Rails mailboxer gem이 메시지를 보낼 수 없다.

class MessagesController < ApplicationController 
    before_action :set_message, only: [:new, :create] 

    def new 
    @message = Message.new 
    end 

    def create 
    current_user.send_message(@recipient, message_params(:body, :subject)) 
    redirect_to conversations_path 
    end 

    private 

    def set_message 
    @recipient = User.find(params[:recipient_id]) 
    end 

    def message_params 
    params.require(:message).permit(:body, :subject) 
    end 
end 

그리고 내보기 :

<h1>New Message</h1> 

<%= simple_form_for(@message, html: {class: "form-horizontal"}) do |f| %> 
    <%= f.error_notification %> 

    <%= f.input :subject %> 
    <%= f.input :body, as: :text, input_html: { rows: "3"} %> 

    <div class="form-actions"> 
    <%= f.button :submit, class: "btn btn-primary" %> 
    </div> 
<% end %> 

하지만 메시지 ... 을 (BTW 내가 메시지가 콘솔로 보낼 수 있으며, 또한 대체 보낼 수 없습니다 "current_user.send_message (@recipient,"테스트 ","테스트 ")"와 메시지 컨트롤러의 일부,하지만 확실히 내가 원하는하지 무슨 일이)

+0

또한 정확한 스택 오류를 게시하면 편리 할 것입니다 ... – David

+1

답변을 알아 냈습니까? 지금 그것을하려고하면 나는 정의되지 않은 모델 이름을 가진 오류가 발생합니다. 나는 보석이 그것을 돌봐야하지 않기 때문에 이해하지 못한다? 메시지 모델을 만들어야합니까? 그렇다면 테이블에 무엇이 필요합니까? – Philip7899

답변

1

를 사용하는 대신 때 form_tag

form_for 대신 form_for를 사용하는이 나를 위해 일한 것처럼

, 때 form_tag를 사용해보십시오 : 당신이 같은

def send_message 
@user = User.find(params[:user_id]) 
@message = params[:message] 
@subject = params[:subject] 
current_user.send_message(@user, "#{@message}", "#{@subject}") 
redirect_to root_path 
end 

그리고 뭔가 :

<%= form_tag("/messages/send_message", method: "post", url: send_message_path) do %> 
<%= hidden_field_tag :user_id, "#{@user.id}" %> 
<%= text_field_tag :subject, nil, :class => 'form-control', :placeholder => "Subject" %> 
<%= text_area_tag :message, nil, :class => 'form-control', :placeholder => "Message" %> 
<%= submit_tag "Submit", :class => "btn btn-primary" %> 
<% end %> 

이는 당신의 메시지 컨트롤러이 같은 조치를 할 것이다 경로 파일 :

post '/messages/send_message', :to => "messages#send_message", :as => "send_message" 

정말 도움이 되길 바랍니다.

관련 문제