Monday, June 13, 2011

[Rails] Devise Authorization Error

Hello everyone,
I am new to rails and I am having some trouble getting the Devise
authorization plugin working. I can get the login page to display, but
when I enter the credentials for a known user (I seeded an account to
the database) it just says "Invalid email or password," even though
I'm 100% sure I entered the right information, and redirects me to the
login form. I'm thinking this might be a namespace problem or
something but I'm not sure.

Here is the relevant code:

--- routes.rb ---
# Root
root :to => "content#index"

# Admin Controllers
namespace 'admin' do
root :to => "admin#index"

# AdminController
devise_for :admin, :path=> '', :path_names => {:sign_in =>
'login', :sign_out => 'logout'}
resources :admin
end

# UsersController
devise_for :users, :path_names => {:sign_in => 'login', :sign_out =>
'logout'}

--- END routes.rb ---

--- admin.rb (Model) ---
class Admin < ActiveRecord::Base

devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable

attr_accessible :email, :password, :password_confirmation, :first_name, :last_name, :superadmin
end

--- END admin.rb ---

--- new.html.erb (The login form) ---
<div class="login_container">
<div class="title_container">Administrator Login</div>
<div class="content_container">
<%= flash[:notice] %>
<%= flash[:alert] %>

<%= form_for(resource, :as => resource_name, :url =>
session_path(resource_name), :html => {:id => :admin_login_form}) do |
f| %>
<table width="100%" cellpadding="2px" cellspacing="0px"
border="0px">
<tr>
<td width="50%">
<%= f.label :email %>
</td>
<td width="50%">
<%= f.email_field :email %>
</td>
</tr>
<tr>
<td width="50%">
<%= f.label :password %>
</td>
<td width="50%">
<%= f.password_field :password %>
</td>
</tr>
<% if devise_mapping.rememberable? -%>
<tr>
<td width="50%">
<%= f.label :remember_me %>
</td>
<td width="50%">
<%= f.check_box :remember_me %>
</td>
</tr>
<% end -%>
</table>
<br /><br />
<%= f.submit "Sign in" %>
<% end %>

<%= render :partial => "devise/shared/links" %>
</div>
</div>

--- END new.html.erb ---

Any help with this would be greatly appreciated!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate