未定义的方法`acts_as_messageable_messages_path` [英] Undefined Method `acts_as_messageable_messages_path`
问题描述
我正在使用行为即讯息(一种铁轨宝石)我有。
然而,在我的messages_controller中,我有
def新
@message = ActsAsMessageable :: Message.new
结束
和in我的观点我有
<%= form_for(@message)do | f | %GT;
引发以下错误:
未定义的方法`acts_as_messageable_messages_path'
我不确定为什么会发生这种情况。请尝试明确指出您希望表单指向哪个路径(这应该是 messages#create
) / code> action):
<%= form_for(@message):url => messages_path,:method => :post do | f | %GT;
< 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 =submitclass =btn primary>发送< / button>
< button type =resetclass =btn>取消< / button>
<%end%>
这里假设你在 routes.rb
$ $ p $ resources:messages
另外,请确保您将必填字段传递给 ActsAsMessageable : https://github.com/LTe/acts-as-messageable/wiki/Example-controller
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.
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
这篇关于未定义的方法`acts_as_messageable_messages_path`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!