问题描述
为什么我不能让我的button_to指定控制器的create动作而不是show
Why can I not get my button_to to specify the create action of my controller rather than show
我已经尝试了无数次添加:action => create以及button_to参数中的其他内容
I have tried numerous times to add :action => "create" and other such things to the button_to parameters
<%= button_to "subscribe", subscription_path(feed_url: @feed.feed_url)%>
我是否需要在route.rb中指定创建路径?
do I need to specify a create route in my routes.rb? if so how should I go about that?
使用该行的方式时,在加载时出现此错误:
When used the way that line is, I get this error on load:
路由错误
没有路由匹配{:action => show,:controller => subscriptions,:feed_url => http:// foo.com/rss}
No route matches {:action=>"show", :controller=>"subscriptions", :feed_url=>"http://foo.com/rss"}
我将其作为订阅的唯一参考。
in routes.rb I have this as the only reference to subscriptions.
resource :subscriptions
推荐答案
您需要使用 subscripton s _path
,而不是 subscription_path
。
You need to use subscriptons_path
, not subscription_path
.
subscription_path
用于显示特定的订阅。
subscriptions_path
用于显示所有订阅(通过GET请求)或创建新订阅(通过POST请求)。
subscription_path
is for showing a specific subscription.subscriptions_path
is for showing all subscriptions (via a GET request) or creating new subscriptions (via a POST request).
<%= button_to "subscribe", subscriptions_path(feed_url: @feed.feed_url, :method => :post)%>
这篇关于Rails:使用button_to创建控制器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!