在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
发布于 2012-03-22 02:05:52
尝试将您的按钮重写为
<form><a href=/home/index><button type="button">Main Menu</button></a></form>发布于 2012-03-22 02:08:21
你的“主菜单”按钮提交了另一个定义好的表单。
你根本不需要<button/>,只要使用简单的link_to "Main menu", home_index_path, :class => :button即可。然后在你的样式表中,让你的链接看起来像按钮:
a.button {
border: 4px outset;
padding: 2px;
text-decoration: none;
}https://stackoverflow.com/questions/9810153
复制相似问题