Undefined Method `acts_as_messageable_messages_path`

巧了我就是萌 提交于 2019-12-11 05:36:15

问题


I'm using acts-as-messageable, a rails gem, in an app i have.

However in my messages_controller i have

def new 
  @message = ActsAsMessageable::Message.new
end 

and in my view i have

<%= form_for(@message) do |f| %>

which throws the following error

undefined method `acts_as_messageable_messages_path'

I'm not really sure why this is happening with the gem.


回答1:


Try explicitly stating what path you want the form to point towards (which should be the messages#create action):

<%= form_for(@message) :url => messages_path, :method => :post do |f| %> 
  <div class="field">
    <%= f.label :to %><br />
    <%= f.email_field :to %>
  </div>
  <div class="field">
    <%= f.label :topic %><br />
    <%= f.text_field :topic %>
  </div>
  <div class="field">
    <%= f.label :body %><br />
    <%= f.text_area :body %>
  </div>

  <button type="submit" class="btn primary">Send</button>
  <button type="reset" class="btn">Cancel</button>
<% end %>

This assumes that you have this in your routes.rb file:

resources :messages

Also, make sure you are passing in the required fields to ActsAsMessageable: https://github.com/LTe/acts-as-messageable/wiki/Example-controller




回答2:


It's because gem doesn't add the route, while form helper tries to generate send URL. Check it with rake routes.



来源:https://stackoverflow.com/questions/8798737/undefined-method-acts-as-messageable-messages-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!