vendredi 17 juillet 2015

Rails[Devise]: devise breaking navbar links

I have a Bootstrap navbar, but the tabs are generated at runtime. It's this way because they link to show/:id and a user can delete the record associated with that tab at any time. I created the links like this:

<% @groups.each do |group| %>
  <li id=<%= group.id %>><%= link_to t("navbar." + group.name.singularize.downcase), :controller => 'groups', :action => 'show', :id => group.id %></li>
<% end %>

This works fine until I use Devise and attempt to get to /admins/sign_in. The navbar code is still exactly the same, but I get an UrlGenerationError:

No route matches {:action=>"show", :controller=>"devise/groups", :id=>4, :locale=>nil}

My guess is the error stems from the controller being "devise/groups" as that's the only difference I spot. Is there a way I can tell it to not prepend "devise"? Or do I have to write new routes for all these bits? If I have to add new routes, how can I use resources in routes?

I suspect Devise also break other links on other pages that I had to code this way.

routes:

Rails.application.routes.draw do
  devise_for :admins
  get 'search/index'
  get 'tags/:tag', to: "search#index", as: :tag

  scope "(:locale)", :locale => /#{I18n.available_locales.join("|")}/ do
    get 'home/index'
    root :to => "home#index"
    resources :brands
    resources :faqs
    resources :categories
    resources :subgroups
    resources :groups
 end

Aucun commentaire:

Enregistrer un commentaire