0

Why can I not get my button_to to specify the create action of my controller rather than show

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)%>

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:

Routing Error

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

1 Answer 1

4

You need to use subscriptons_path, not subscription_path.

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)%>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.