model - Rails TypeError when passing a object -
i creating tableless model in rails 4 supporting sending emails easily.
so have following model:
class message include activemodel::model attr_accessor :subject, :content, :email end the following controller:
class messagescontroller < applicationcontroller def new @message = message.new end def create message = message.new(params[:message]) if message.valid? usermailer.send(message) redirect_to :back, :notice => "email sent." else flash[:alert] = "you must fill fields." render 'new' end end end the form:
<%= form_for @message |f| %> <%= f.label :email %> <%= f.text_field :email %> <%= f.label :subject %> <%= f.text_field :subject %> <%= f.label :content %> <%= f.text_area :content, rows: 5, class: 'span7' %> <%= f.submit "send email", class: 'btn btn-primary' %> <% end %> but when try send email here got:
#<message:0x007fcc98e8c760 @errors=# <activemodel::errors:0x007fcc98e96788 @base=#<message:0x007fcc98e8c760 ...>, @messages={}>, @email="sdsadas@adasdas.com", @subject="adasdas", @content="asdsad", @validation_context=nil> not symbol the error says in here usermailer.send(message)
can me?
the kernel.send method you're calling on usermailer accepts symbol or string, whereas you're attempting pass instance of message. you're looking other method of usermailer. you'll defining , calling own method on actionmailer::base subclass. see the guide details.
Comments
Post a Comment