我刚安装了Devise,现在我想为Devise打造更好的风格。我已经在application.html.rb链接中添加了编辑Devise用户配置文件,但是当我访问此页面然后返回到例如索引页面时,我没有路由匹配错误。
HTML为home / index生成此链接:http://localhost:3000/assets?controller=devise%2Fhome
但确实需要:http://localhost:3000/home/index
访问Devise用户页面后出现问题。
我的导航:
<ul>
<li>
<h2>Izvēlne</h2>
<ul>
<li><a class="menu"><%= link_to "Jaunumi" ,:controller=>"home", :action => "index" %></a></li>
<li><a class="menu"><%= link_to "Par skolu" ,:controller=>"home", :action => "par_skolu" %></a></li>
<li><a class="menu"><%= link_to "Galerijas" ,:controller=>"home", :action => "galerijas" %></a></li>
<li><a class="menu"><%= link_to "Skolotāji" ,:controller=>"home", :action => "personals" %></a></li>
<li><a class="menu"><%= link_to "Kontaktinformācija" ,:controller=>"home", :action => "kontakti" %></a></li>
<li><a class="menu"><%= link_to "Personāla pieeja" ,:controller=>"home", :action => "pers_pieeja" %></a></li>
</ul>
</li>
<li>
<h2>Administrācija</h2>
<ul>
<li><%= link_to "Lietotāju rediģēšana", edit_user_registration_path %></li>
<li><%= link_to "Rakstu rediģēšana" ,:controller=>"posts", :action => "index" %></li>
<li><%= link_to "Galeriju rediģēšana" ,:controller=>"admin", :action => "galeriju_red" %></li>
</ul>
</li>
</ul>
routes.rb中:
devise_for :users
get "admin/galeriju_red"
resources :posts
get "admin/rakstu_red"
get "home/par_skolu"
get "home/personals"
get "home/kontakti"
get "home/pers_pieeja"
get "home/galerijas"
get "home/index"
答案 0 :(得分:2)
我能想到的唯一想法是改变你的路线:
get "home/index"
到
match "/home/index" => "home#index", :via => [:get]
它们是等效的,但匹配会使路径助手可用,因此菜单视图中的链接可能如下所示:
<%= link_to "Home" main_app.home_index_path %>
Main_app是一个内置的Rails助手,可以访问Engine内部的Rails路由。
如果你简单匹配/ home,路径助手将被称为home_path。
我希望这可以解决您的问题。