Вопрос

I have an application under development in Rails 3.2.13 with devise, omniauth and cancan. It all worked perfectly until I started to implement authorisation with cancan. It is even more interesting that cancan itself works like charm but generates an error in editing the user profile provided by devise. If cancan does that at all, I'm really not sure.

The error message is:

No route matches {:controller=>"devise/posts"}

I have a posts controller, but that's not linked to devise by any means. This is the strangest part in the story.

I successfully localised the spot that generates it but I can't figure out what the cause of the problem is and how to fix it. So I have a menu shown only to admins in my application.html.erb , this is the source:

<% if (user_signed_in? && (current_user.role?("sysadmin") || current_user.role?("postadmin") || current_user.role?("testadmin")))  %>

    <ul class="nav navbar-nav nav-pills">
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" style="color: crimson;">
                <span class="glyphicon glyphicon-cog"></span> Administration <b class="caret"></b></a>
            <ul class="dropdown-menu">
                <% if (current_user.role?("sysadmin") || current_user.role?("postadmin")) then %>
                    <li><%= link_to 'Posts', :controller => :posts, :action => :index %></li>
                <% end %>
                <% if (current_user.role?("sysadmin") || current_user.role?("testadmin")) then %>
                    <li><%= link_to 'Itests', :controller => :itests, :action => :index %></li>
                <% end %>
            </ul>
        </li>
    </ul>

<% end %>

What's really interesting is that if I delete the <ul>...</ul> block so to leave nothing but a naked if ... end block, it works. Also, it works for users not having any of the three admin roles.

But in the <ul>...</ul> block there's nothing else but HTML, Bootstrap styling and some inline ruby links to some other controllers.

How does this breaks the "edit profile" feature of devise?

Это было полезно?

Решение

Check out this question: Rails No route matches {:controller=>"devise/products"}

Basically you're in device namespace and you have to use path helpers:

<%= link_to 'Posts', posts_path %>

or:

<%= link_to 'Posts', :controller => '/posts', :action => :index %>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top