开发者

Routes won't work for form_tag helper

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_devices is your named route. Rails automatically generates two methods per named route as route helpers for you. They are always named in the following convention:

named_route_path
named_route_url

You can use either (although path is usually encouraged). Using choose_devices_path will return /account/devices/choose whereas choose_devices_url will return something like localhost:3333/account/devices/choose or 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 _url named route helper, so not sure on that part).

You can also read up on these specifically at the rails routing guide.


You need to append _path ie.

choose_devices_path
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜