问题
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