开发者

Getting Exception trying to add a field in the form using devise (customize devise)?

I am trying to to add a field first name in my form ,I have changed in the view template,user model,updated the table(rails g add_firstname_to user firstname:string migration).But i am still getting an exception undefined method `firstname' for #. what am i missing ?my file looks like this

view

<h2>Sign up</h2>
<%= form_for(resource_name, resource, :url => registration_path(resource_name)) do   |f|     %>
  <%= f.error_messages %>
<table>
  <tr><td><label>First name</label></td>
  <td><%= f.text_field :firstname %></td&开发者_高级运维gt;</tr>


  <tr><td><label>Email</label></td>
  <td><%= f.text_field :email %></td></tr>

   <tr><td><%= f.label :password %></td>
<td><%= f.password_field :password %></td></tr>

<tr><td><%= f.label :password_confirmation %></td>
<td><%= f.password_field :password_confirmation %></td></tr>

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

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

User model class

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :lockable, :timeoutable and :activatable
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation,:firstname
end


This step by step tutorial will tell you everything. :)

Looking at your code, two suggestions:

  • You said you runned rails g add_firstname_to user firstname:string migration I hope this is a typo in here, but you should use add_firstname_to_users - Notice the s on user.

  • As the first comment suggests, did you run rake db:migrate ?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜