【发布时间】:2012-03-21 17:54:45
【问题描述】:
在 Ruby on Rails 表单中,我尝试使用按钮而不是 link_to 返回主菜单。我使用了以下内容(我在浏览这个论坛时发现的):
<form><a href=/home/index><button>Main Menu</button></a></form>
如果我将鼠标悬停在按钮上,我会看到 http://172.19.95.56:3005/home/index,这是我可以在浏览器上看到的有效页面,这就是我希望按钮将我带到的地方,但如果我单击该按钮,它需要我到http://172.19.95.56:3005/l2vpns/1/edit,我在 Rails 服务器上看到以下日志:
Started GET "/l2vpns/1/edit" for 172.24.67.151 at 2012-03-21 10:44:26 -0700
Processing by L2vpnsController#edit as HTML
Parameters: {"id"=>"1"}
L2vpn Load (0.4ms) SELECT "l2vpns".* FROM "l2vpns" WHERE "l2vpns"."id" = ? LIMIT 1 [["id", "1"]]
Rendered l2vpns/_form.html.erb (65.7ms)
Rendered l2vpns/edit.html.erb within layouts/application (66.5ms)
Completed 200 OK in 81ms (Views: 76.6ms | ActiveRecord: 1.2ms)
我的路线如下:
[root@localhost pocplus]# rake routes
apply_configs_l2vpns GET /l2vpns/apply_configs(.:format) {:action=>"apply_configs", :controller=>"l2vpns"}
l2vpns GET /l2vpns(.:format) {:action=>"index", :controller=>"l2vpns"}
POST /l2vpns(.:format) {:action=>"create", :controller=>"l2vpns"}
new_l2vpn GET /l2vpns/new(.:format) {:action=>"new", :controller=>"l2vpns"}
edit_l2vpn GET /l2vpns/:id/edit(.:format) {:action=>"edit", :controller=>"l2vpns"}
l2vpn GET /l2vpns/:id(.:format) {:action=>"show", :controller=>"l2vpns"}
PUT /l2vpns/:id(.:format) {:action=>"update", :controller=>"l2vpns"}
DELETE /l2vpns/:id(.:format) {:action=>"destroy", :controller=>"l2vpns"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
/:controller(/:action(/:id(.:format)))
root / {:controller=>"home", :action=>"index"}
[root@localhost pocplus]#
谁能告诉我我做错了什么?为什么按钮进入“编辑”页面而不是 /home/index 页面?
如果此信息很重要,我使用的是 Firefox 11.0
【问题讨论】:
标签: ruby-on-rails button routes link-to