In a Ruby on Rails form, I’m trying to use a button instead of link_to to go back to a main menu. I used the following (which I found from browsing this forum) :
<form><a href=/home/index><button>Main Menu</button></a></form>
If I mouse over the button, I see http://172.19.95.56:3005/home/index, which is a valid page that I can see on my browser, and that’s where I want the button to take me, but if I click on that button, it takes me to http://172.19.95.56:3005/l2vpns/1/edit, and I see the following logs on the Rails server :
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)
My routes are the following:
[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]#
Anyone can tell me what am I doing wrong? Why does the button take to the “edit” page and not the /home/index one?
If this info is important, I’m using Firefox 11.0
Try rewriting your button as
The default type for a button in most browsers is “submit”, so it’s trying to submit your form.