Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RoR:按钮而不是链接到的链接不会转到同一页_Ruby On Rails_Button_Routes_Link To - Fatal编程技术网

Ruby on rails RoR:按钮而不是链接到的链接不会转到同一页

Ruby on rails RoR:按钮而不是链接到的链接不会转到同一页,ruby-on-rails,button,routes,link-to,Ruby On Rails,Button,Routes,Link To,在RubyonRails表单中,我尝试使用按钮而不是链接返回主菜单。我使用了以下内容(我在浏览本论坛时发现): 我的路线如下: [root@localhost pocplus]# rake routes apply_configs_l2vpns GET /l2vpns/apply_configs(.:format) {:action=>"apply_configs", :controller=>"l2vpns"} l2vpns GET /

在RubyonRails表单中,我尝试使用按钮而不是链接返回主菜单。我使用了以下内容(我在浏览本论坛时发现):

我的路线如下:

[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,请尝试将您的按钮改写为

<form><a href=/home/index><button type="button">Main Menu</button></a></form>

在大多数浏览器中,按钮的默认类型是“提交”,因此它试图提交您的表单。

您的“主菜单”按钮提交了其中定义的另一个表单

您根本不需要
,只需使用简单的
链接到“主菜单”,主索引路径:class=>:按钮即可。然后在样式表中,使链接看起来像按钮:

a.button {
  border: 4px outset;
  padding: 2px;
  text-decoration: none;
}

感谢Nash Bridges,我尝试了这个,但它抱怨home_path“未定义的局部变量或方法'home_path'”@rh4games当然,我应该更加注意。更正url帮助程序。谢谢niiru,这对我来说很有效,但是按钮内的文本像超文本一样带下划线,有没有办法不带下划线?我知道这是装饰性的,但我希望我所有的按钮都是一样的。你可以将该链接的CSS文本装饰样式设置为“无”:我在Firefox中实现了这一功能,但现在在IE9中无法实现;有什么想法吗?
<form><a href=/home/index><button type="button">Main Menu</button></a></form>
a.button {
  border: 4px outset;
  padding: 2px;
  text-decoration: none;
}