I’m using Devise and Can-Can for my community blog and currently looking for a way to re-direct ‘only’ the Admins and Moderators to the views/admin/index page directly once they sign in. Not sure if I can do this in the routes.rb or Sign In form? Any help appreciated…
application_controller
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from CanCan::AccessDenied do |exception|
flash[:alert] = exception.message
redirect_to root_url
end
end
routes.rb file
root :to => "articles#index"
sessions/new.html.erb
<h2>Sign In</h2>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<p><%= f.label :email %><br />
<%= f.text_field :email %></p>
<p><%= f.label :password %><br />
<%= f.password_field :password %></p>
<% if devise_mapping.rememberable? -%>
<p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
<% end -%>
<p><%= f.submit "Sign In" %></p>
<% end %>
error
NoMethodError in Devise/sessionsController#create -
Application Trace | Framework Trace | Full Trace
app/controllers/application_controller.rb:11:in `after_sign_in_path_for'
In your
application_controlleradd something like this:Alternative (for Devise 1.1.x):