I’m a Rails 3 newbie so I must be doing something stupid here as almost all my routes are not working with the form_tag helper. I’ve broke it down to the simplest example:
<%= form_tag(choose_devices) do %>
<% end %>
Rake routes is showing the route:
choose_devices POST /account/devices/choose(.:format)
{:action=>"choose", :controller=>"devices"}
The error I’m getting when trying to load the page is:
undefined local variable or method `choose_devices' for
#<#<Class:0x00000100d8e270>:0x00000100d7efa0>
I tried various routes to test with and it only seems to work with this one:
user_session POST /users/sign_in(.:format)
{:action=>"create", :controller=>"devise/sessions"}
What am I doing wrong here?
choose_devicesis your named route. Rails automatically generates two methods per named route as route helpers for you. They are always named in the following convention:You can use either (although path is usually encouraged). Using
choose_devices_pathwill return/account/devices/choosewhereaschoose_devices_urlwill return something likelocalhost:3333/account/devices/chooseor it actually may error out if you do not set your host appropriately in config files (it’s been a long time since I explicitly used a_urlnamed route helper, so not sure on that part).You can also read up on these specifically at the rails routing guide.