1

This should be an easy question, but I just can't figure it out. I want to trigger an action (which just renders a page) through a button using "button_to" in view:

<%= button_to "Fresh", action: 'fresh', method: 'get' %>

The error says "No route matches [POST] "/static_pages/fresh"". It seems that the button still uses "post" instead the "get". Meanwhile, if I use "link_to", it works fine.

<%= link_to "Fresh", action: 'fresh', method: 'get' %>

Thanks for any comments and help.

2
  • what controller is the fresh action on? Can you show your routes.rb file? Commented Apr 26, 2013 at 2:38
  • "Fresh" is in the "static_pages controller". In my point of view, "button_to" is similar to "link_to", which works fine in the same view. Commented Apr 26, 2013 at 4:55

1 Answer 1

2

Try this

<%= button_to "delete", {:controller => :static_pages, :action => 'fresh'}, :method => :get %>

Also check your routes.rb to ensure that the route to fresh is defined.

Sign up to request clarification or add additional context in comments.

2 Comments

It works. Why does "link_to" doesn't need to specify the controller while "button_to" needs? Weird.
Actually, I am almost positive that button_to doesn't need the controller either. I don't believe you should have any problems deleting that part if you wish. The real problem with your initial code wasn't that; rather it was due to brackets not being there.

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.