开发者

weird devise/rails issue not sending username

I have added username to a devise authentication setup, and for some reason, it's not inserting the username into the database. The database puts NULL in the username field.

I have included code for the migration, and the form, as well as the production log that shows that it sent the actual username.

Here is what I did:

So I added a migration to add a username, which was successful:

class AddUsernameToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :username, :string
  end

  def self.down
    remove_column :users, :username
  end
end

I then edited app/views/devise/registrations/new.html.erb to include a text field for username:

<h2>Sign up</h2>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <开发者_如何学JAVA%= devise_error_messages! %>

  <p><%= f.label :username %><br />
  <%= f.text_field :username %></p>

  <p><%= f.label :email %><br />
  <%= f.text_field :email %></p>

  <p><%= f.label :password %><br />
  <%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></p>

  <p><%= f.submit "Sign up" %></p>
<% end %>

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

Here is the production log if that helps:

Started POST "/users" for 136.152.162.173 at Wed Feb 23 12:46:12 -0800 2011
  Processing by Devise::RegistrationsController#create as HTML
  Parameters: {"commit"=>"Sign up", "authenticity_token"=>"K8m6Em7IqSTFQG8aAYE4faUMsL2E46uNAllNTcsEF08=", "utf8"=>"?~\~S", "user"=>{"password_confirmation"=>"[FILTERED]", "username"=>"pyramation", "password"=>"[FILTERED]", "email"=>"dan@email.com"}}
Rendered devise/mailer/confirmation_instructions.html.erb (1.1ms)

Any help is greatly appreciated!


Have you added :username to your attr_accessible list in your User model? e.g.:

attr_accessible :email, :password, :password_confirmation, :username
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜