Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 0.80 KB  |  hits: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to redirect to users/:id after successful devise sign in - rails 3
  2. def after_sign_in_path_for(resource)
  3.   dashboard_path
  4. end
  5.        
  6. devise_for :users,:has_many => :comments, :controllers => {:sessions => devise/sessions', :registrations => 'devise/registrations'} do      
  7.  
  8.        match '/users/:id/dashboard', :to => "users#dashboard", :as => :dashboard
  9.        
  10. def resource_name    
  11.      :user    
  12.  end    
  13.  
  14.  def resource    
  15.     @resource ||= User.new    
  16.   end    
  17.  
  18.   def devise_mapping    
  19.     @devise_mapping ||= Devise.mappings[:user]      
  20.   end      
  21.  
  22.  end
  23.        
  24. def after_sign_in_path_for(resource)    
  25.      if current_user.admin?    
  26.       stored_location_for(resource) || admin_path    
  27.     else      
  28.        stored_location_for(resource) || dashboard_path(current_user.id)      
  29.      end      
  30.   end