Manage users through a CRUD interface with devise errors - ruby-on-rails

I have establish a Crud interface with devise below my code, the problem that I am running into is that When I try to create a user a get the following errors. I can't edit either. Please help.
"2 errors prohibited this user from being saved:
Email can't be blank
Password can't be blank"
of course I have been entering all of the information inclduding email and password. I follow the documentation from devise and have read some of this site Devise topics no such problem reported.
Controller:
class UsersController < ApplicationController
before_filter :authenticate_user!
before_action :authorized_user
# GET /users
# GET /users.json
def index
#users = User.all
# respond_to do |format|
# format.html index.html.erb
# format.json { render :json => #users }
end
# GET /users/1
# GET /users/1.json
def show
#user = User.find(params[:id])
# respond_to do |format|
# format.html show.html.erb
# format.json { render :json => #user }
end
# GET /users/new
# GET /users/new.json
def new
#user = User.new
# respond_to do |format|
# format.html new.html.erb
# format.json { render :json => #user }
end
# GET /users/1/edit
def edit
#user = User.find(params[:id])
end
# POST /users
# POST /users.json
def create
#user = User.new(params[:user_params])
respond_to do |format|
if #user.save
format.html { redirect_to #user, :notice => 'User was successfully created.' }
format.json { render :json => #user, :status => :created, :location => #user }
else
format.html { render :action => "new" }
format.json { render :json => #user.errors, :status => :unprocessable_entity }
end
end
end
# PUT /users/1
# PUT /users/1.json
def update
if params[:user][:password].blank?
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
end
#user = User.find(params[:id])
respond_to do |format|
if #user.update_attributes(params[:user_params])
format.html { redirect_to #user, :notice => 'User was successfully updated.' }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => #user.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
#user = User.find(params[:id])
#user.destroy
respond_to do |format|
format.html { redirect_to users_url }
format.json { head :ok }
end
end
private
def user_params
params.require(:user).permit(:username, :name, :lastname, :email, :password, :password_confirmation, :role_id)
end
def authorized_user
if current_user.role.name == "admin"
else
redirect_to :root, notice: "Not authorized" if #current_user.role.name == 'user' or nil?
end
end
end
Here is my form:
<%= form_for(#user) do |f| %>
<% if #user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% #user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :username %><br />
<%= f.text_field :username, autofocus: true %>
</div>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true %>
</div>
<div class="field">
<%= f.label :lastname %><br />
<%= f.text_field :lastname, autofocus: true %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %>
<% if #minimum_password_length %>
<em>(<%= #minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :role_id %><br />
<%= f.collection_select :role_id, Role.all, :id, :name_role_select %>
</div>
<div class="actions">
<%= f.submit "Sign up", class: 'button' %>
</div>

You aren't properly using your user_params.
Instead of this in your create action:
User.new(params[:user_params])
You need this, which calls your user_params method which is defined in your controller:
User.new(user_params)
Your original way is looking for params passed in from your request called 'user_params'(which doesn't exist).
Similarly, for your update action you need:
if #user.update_attributes(user_params)
#etc...

Related

param is missing or the value is empty: user when tring to add a user

Hi I know this has been asked many times but none of those could help me.
I'm building an online clinic website based on ruby on rails.
When a user wants to sign up it chooses either Doctor or Patient. After that a sign-in form appears.
In DB, there's a general table for users for common attributes like name, gender etc. In that table the user type in set. For Doctor and Patient there are two separate tables for their specific attributes.
Here's the problem!
When signing up I get the error: raise ParameterMissing.new(key)
Here's thee code for doctor_controller.rb:
class DoctorsController < ApplicationController
before_action :set_doctor, only: [:show, :edit, :update, :destroy]
#before_save :set_type
# GET /doctors
# GET /doctors.json
def index
#doctors = Doctor.all
end
# GET /doctors/1
# GET /doctors/1.json
def show
end
# GET /doctors/new
def new
#doctor = Doctor.new
#user=User.new
#user.user_type='2'
end
# GET /doctors/1/edit
def edit
end
# POST /doctors
# POST /doctors.json
def create
#user=User.new(user_params)
respond_to do |format|
if #user.save
format.html { redirect_to #user, notice: 'Doctor was successfully created.' }
format.json { render :show, status: :created, location: #doctor }
else
format.html { render :new }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
#doctor = Doctor.new(doctor_params)
respond_to do |format|
if #doctor.save
format.html { redirect_to #doctor, notice: 'Doctor was successfully created.' }
format.json { render :show, status: :created, location: #doctor }
else
format.html { render :new }
format.json { render json: #doctor.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /doctors/1
# PATCH/PUT /doctors/1.json
def update
respond_to do |format|
if #doctor.update(doctor_params)
format.html { redirect_to #doctor, notice: 'Doctor was successfully updated.' }
format.json { render :show, status: :ok, location: #doctor }
else
format.html { render :edit }
format.json { render json: #doctor.errors, status: :unprocessable_entity }
end
end
end
# DELETE /doctors/1
# DELETE /doctors/1.json
def destroy
#doctor.destroy
respond_to do |format|
format.html { redirect_to doctors_url, notice: 'Doctor was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_doctor
#doctor = Doctor.find(params[:id])
#user = User.find(params[:id])
end
def set_type
#user.user_type="2"
end
# Never trust parameters from the scary internet, only allow the white list through.
def doctor_params
params.require(:doctor).permit(:user_id, :doctroNum, :adderess, :sepciality, :records)
end
def user_params
params.require(:user).permit(:user_type, :username, :password, :name, :family, :gender, :phone, :city, :profilepicture)
end
end
and here is the code for signup form:
<%= form_for(#user) do |f| %>
<% if #user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% #user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :username, "Email" %><br>
<%= f.email_field :username %>
</div>
<div class="field">
<%= f.label :password %><br>
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :family %><br>
<%= f.text_field :family %>
</div>
<div class="field">
<%= f.label :gender %><br>
<%= f.text_field :gender %>
</div>
<div class="field">
<%= f.label :phone %><br>
<%= f.text_field :phone %>
</div>
<div class="field">
<%= f.label :city %><br>
<%= f.text_field :city %>
</div>
<% end %>
<%= form_for(#doctor) do |f| %>
<% if #doctor.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#doctor.errors.count, "error") %> prohibited this doctor from being saved:</h2>
<ul>
<% #doctor.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :doctroNum %><br>
<%= f.text_field :doctroNum %>
</div>
<div class="field">
<%= f.label :adderess %><br>
<%= f.text_field :adderess %>
</div>
<div class="field">
<%= f.label :sepciality %><br>
<%= f.text_field :sepciality %>
</div>
<div class="field">
<%= f.label :records %><br>
<%= f.text_field :records %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
I know it's too much. I'd be really thankful
There is no f.submit button for form_for(#user), so whenever you press the submit button, the form_for(#doctor)'s submit button gets called. Hence, the params that are sent forward, always include doctor, and never include user. But the code in your create method expects params to have user in it: #user = User.new(user_params) - therefore, it is generating param is missing or the value is empty: user.
Apart from it, you are not following the good practices. You controller name is DoctorsController, but you are mixing it with the user's code. You should have two separate controllers: DoctorsController, UsersController, and accordingly two different views.

Ruby on Rails Drop Down Box not committing to database (Model)

I have a rails form to collect information on people for a family tree application. There are two drop down boxes that are used to assign the parents of the person being edited/created, however when a selection is made in either, or both, of these boxes, it is not committed to the database. It doesn't throw any exceptions, however when I check the database, the fatherID and motherID fields remain as null.
Here is the complete code for the form:
Does anybody have any ideas where I'm going astray?
Thanks.
<%= form_for(#person) do |f| %>
<% if #person.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#person.errors.count, "error") %> prohibited this person from being saved:</h2>
<ul>
<% #person.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :FirstName %><br>
<%= f.text_field :FirstName %>
</div>
<div class="field">
<%= f.label :LastName %><br>
<%= f.text_field :LastName %>
</div>
<div class="field">
<%= f.label :MaidenName %><br>
<%= f.text_field :MaidenName %>
</div>
<div class="field">
<%= f.label :Sex %><br>
<%= f.select(:Sex, options_for_select([['Male', 'M'], ['Female', 'F']]))%>
</div>
<div class="field">
<p>Parents:</p>
Mother: <%= select(:motherID, options_from_collection_for_select(Person.all, :id, :FirstName), :include_blank => true)%>
Father: <%= select(:fatherID, options_from_collection_for_select(Person.all, :id, :FirstName), :include_blank => true)%>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Controller code
class PeopleController < ApplicationController
before_action :set_person, only: [:show, :edit, :update, :destroy]
# GET /people
# GET /people.json
def index
#people = Person.all
end
# GET /people/1
# GET /people/1.json
def show
end
# GET /people/new
def new
#person = Person.new
end
# GET /people/1/edit
def edit
end
# POST /people
# POST /people.json
def create
#person = Person.new(person_params)
respond_to do |format|
if #person.save
format.html { redirect_to #person, notice: 'Person was successfully created.' }
format.json { render action: 'show', status: :created, location: #person }
else
format.html { render action: 'new' }
format.json { render json: #person.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /people/1
# PATCH/PUT /people/1.json
def update
respond_to do |format|
if #person.update(person_params)
format.html { redirect_to #person, notice: 'Person was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #person.errors, status: :unprocessable_entity }
end
end
end
# DELETE /people/1
# DELETE /people/1.json
def destroy
#person.destroy
respond_to do |format|
format.html { redirect_to people_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_person
#person = Person.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def person_params
params.require(:person).permit(:FirstName, :LastName, :MaidenName, :Sex)
end
end
Model Code
class Person < ActiveRecord::Base
has_ancestry
end
:motherID and :fatherID need to be in params.require(:person).permit(:FirstName, :LastName, :MaidenName, :Sex) otherwise the controller does not pass these values to the model for them to be saved.
For more information about strong parameters, see the rails guide: http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters

Ruby on rails scaffold error in _form.html.erb

This CURD generated by scaffold method using following command
rails g scaffold contact fullname:string surname:string email:string mobile:string note:text
when i go to localhost:3003/contacts/new getting following error
NoMethodError in Contacts#new
Showing /root/contactlist/app/views/contacts/_form.html.erb where line #16 raised:
undefined method `fullname' for #<Contact:0xb2fa75b4>
Extracted source (around line #16):
13:
14: <div class="field">
15: <%= f.label :fullname %><br />
16: <%= f.text_field :fullname %>
17: </div>
18: <div class="field">
19: <%= f.label :surname %><br />
Trace of template inclusion: app/views/contacts/new.html.erb
Rails.root: /root/contactlist
Application Trace | Framework Trace | Full Trace
app/views/contacts/_form.html.erb:16:in `_app_views_contacts__form_html_erb___387033993__645411558'
app/views/contacts/_form.html.erb:1:in `_app_views_contacts__form_html_erb___387033993__645411558'
app/views/contacts/new.html.erb:3:in `_app_views_contacts_new_html_erb__1061805842__644918458'
app/controllers/contacts_controller.rb:29:in `new'
This is my views/contacts/_form.html.erb
<%= form_for(#contact) do |f| %>
<% if #contact.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#contact.errors.count, "error") %> prohibited this contact from being saved:</h2>
<ul>
<% #contact.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :fullname %><br />
<%= f.text_field :fullname %>
</div>
<div class="field">
<%= f.label :surname %><br />
<%= f.text_field :surname %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :mobile %><br />
<%= f.text_field :mobile %>
</div>
<div class="field">
<%= f.label :note %><br />
<%= f.text_area :note %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
this is the Controller file "contacts_controller.rb"
class ContactsController < ApplicationController
# GET /contacts
# GET /contacts.json
def index
#contacts = Contact.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => #contacts }
end
end
# GET /contacts/1
# GET /contacts/1.json
def show
#contact = Contact.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => #contact }
end
end
# GET /contacts/new
# GET /contacts/new.json
def new
#contact = Contact.new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => #contact }
end
end
# GET /contacts/1/edit
def edit
#contact = Contact.find(params[:id])
end
# POST /contacts
# POST /contacts.json
def create
#contact = Contact.new(params[:contact])
respond_to do |format|
if #contact.save
format.html { redirect_to #contact, :notice => 'Contact was successfully created.' }
format.json { render :json => #contact, :status => :created, :location => #contact }
else
format.html { render :action => "new" }
format.json { render :json => #contact.errors, :status => :unprocessable_entity }
end
end
end
# PUT /contacts/1
# PUT /contacts/1.json
def update
#contact = Contact.find(params[:id])
respond_to do |format|
if #contact.update_attributes(params[:contact])
format.html { redirect_to #contact, :notice => 'Contact was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => #contact.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /contacts/1
# DELETE /contacts/1.json
def destroy
#contact = Contact.find(params[:id])
#contact.destroy
respond_to do |format|
format.html { redirect_to contacts_url }
format.json { head :no_content }
end
end
end
This is the Model file "contact.rb"
class Contact < ActiveRecord::Base
attr_accessible :email, :fullname, :mobile, :note, :surname
end
Please help me solve this error i'm stuck.
Everything looks right. Run rake db:migrate then restart the server.
Edit:
if you have created the table already and you want to recreate it then drop the old table first
Add this to the top of the migration
def change
drop_table contacts
.... #create the new contact table
end

Rails posts show up blank, not saving

I tried to submit a new post and I get the error
"Title can't be blank"
So I removed the validations in my model and after trying again and posting something, the post is just blank, no data is saved whatsoever.
I don't know what to do, I stuck on this one, help!
Update!
Here is the form
<% #post.tags.build %>
<%= form_for #post, :html => {:multipart => true } do |post_form| %>
<% if #post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#post.errors.count, "error") %> prohibited this post from being saved: </h2>
<ul>
<% #post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= post_form.file_field :photo %>
</div>
<div class="field">
<%= post_form.label :title %><br />
<%= post_form.text_field :title %>
</div>
<div class="field">
<%= post_form.label :url %><br />
<%= post_form.text_field :url %>
</div>
<div class="field">
<%= post_form.label :company %><br />
<%= post_form.text_field :company %>
</div>
<div class="field">
<%= post_form.label :language %><br />
<%= post_form.text_field :language %>
</div>
<div class="field">
<%= post_form.label :framework %><br />
<%= post_form.text_field :framework %>
</div>
<div class="field">
<%= post_form.label :details %><br />
<%= post_form.text_area :details %>
</div>
<h2>Tags</h2>
<%= render :partial => 'tags/form' ,
:locals => {:form => post_form } %>
<div class="actions">
<%= post_form.submit %>
</div>
<% end %>
here is the controller:
class PostsController < ApplicationController
http_basic_authenticate_with :name => "franklinexpress", :password => "osxuser8", :except => [:index, :show, :new, :edit]
#def search
# #posts = Post.search(params[:search])
# end
# GET /posts
# GET /posts.json
def index
#posts = Post.search(params[:search])
# #posts = Post.all
# respond_to do |format|
#format.html # index.html.erb
#format.json { render json: #posts }
#end
end
# GET /posts/1
# GET /posts/1.json
def show
#post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: #post }
end
end
# GET /posts/new
# GET /posts/new.json
def new
#post = Post.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: #post }
end
end
# GET /posts/1/edit
def edit
#post = Post.find(params[:id])
end
# POST /posts
# POST /posts.json
def create
#post = Post.new(params[:post])
respond_to do |format|
if #post.save
format.html { redirect_to #post, notice: 'Post was successfully created.' }
format.json { render json: #post, status: :created, location: #post }
else
format.html { render action: "new" }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
# PUT /posts/1
# PUT /posts/1.json
def update
#post = Post.find(params[:id])
respond_to do |format|
if #post.update_attributes(params[:post])
format.html { redirect_to #post, notice: 'Post was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.json
def destroy
#post = Post.find(params[:id])
#post.destroy
respond_to do |format|
format.html { redirect_to posts_url }
format.json { head :ok }
end
end
end
in my model:
class Post < ActiveRecord::Base
validates :title, :presence => true
validates :url, :presence => true
validates :company, :presence => true
validates :language, :presence => true
validates_attachment_size :photo, :less_than => 4.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']
has_many :comments, :dependent => :destroy
has_many :tags
attr_accessor :photo_file_name
attr_accessor :photo_content_type
attr_accessor :photo_file_size
attr_accessor :photo_updated_at
attr_accessible :photo
accepts_nested_attributes_for :tags, :allow_destroy => :true,
:reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
#paperclip-------------------------------
has_attached_file :photo,
:url => "/assests/images/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/images/:id/:style/:basename.:extension"
#:style => {:small => "150x200>"}
def self.search(search)
if search
where('title LIKE ?', "%#{search}%")
# find(:all, :conditions => ['title LIKE ?', "%#{search}%"])
else
all
end
end
end
and in new.html.erb:
<div id="header-wrap">
<%= image_tag("walLogotiny.png") %>
<div id="searchbartop">
<%= form_tag posts_path, :method => :get do%>
<%= text_field_tag :search, params[:search] ,"size" => 100 %>
<%= submit_tag "Search", :name => nil %>
<% end %>
</div>
</div>
<div id="container">
<h2>New Site Submission</h2>
<%= render 'form' %>
<%= link_to 'Back', posts_path %>
</div>
With this line in your model:
attr_accessible :photo
You make only the photo attribute mass-assignable. All other attributes, including the title, are dropped when you create a new post.
Try this:
attr_accessible :photo, :title
It will now accept the title, but not the other attributes.
edit: didn't see your own comment above, but you figured it out already.

Namespaced Controller cannot find model virtual attribute method

I get the following error with the supplied code.
undefined method `password' for #<User:0x00000002e66980>
User Model
class User < ActiveRecord::Base
validates_presence_of :username
validates_presence_of :first_name
validates_presence_of :last_name
validates_presence_of :email
validates_uniqueness_of :username
validates_uniqueness_of :email
attr_accessor :password_confirmation
validates_confirmation_of :password
validate :password_non_blank
# password is a virtual attribute
def password=(pwd)
#password = pwd
return if pwd.blank?
create_new_salt
self.hashed_password = self.class.encrypt_password(pwd, self.password_salt)
end
def self.authenticate(username, password)
if user = self.find_by_username(username)
if user.hashed_password == encrypt_password(password, user.password_salt)
user
end
end
end
def User.encrypt_password(password, password_salt)
string_to_hash = password + "woozlewozzle" + password_salt
Digest::SHA1.hexdigest(string_to_hash)
end
private
def password_non_blank
errors.add(:password, "Password cannot be blank.") if hashed_password.blank?
end
def create_new_salt
self.password_salt = self.object_id.to_s + rand.to_s
end
end
Users Controller
class Admin::UsersController < Admin::AdminController
skip_before_filter :authorize
# GET /users
# GET /users.xml
def index
#users = User.find(:all, :order => :username)
respond_to do |format|
format.html # index.html.erb
end
end
# GET /users/1
# GET /users/1.xml
def show
#user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
end
end
# GET /users/new
# GET /users/new.xml
def new
#user = User.new
respond_to do |format|
format.html # new.html.erb
end
end
# GET /users/1/edit
def edit
#user = User.find(params[:id])
end
# POST /users
# POST /users.xml
def create
#user = User.new(params[:user])
respond_to do |format|
if #user.save
flash[:notice] = "User #{#user.first_name} #{#user.last_name} was created successfully."
format.html { redirect_to(:action => 'index') }
else
format.html { render :action => 'new' }
end
end
end
# PUT /users/1
# PUT /users/1.xml
def update
#user = User.find(params[:id])
respond_to do |format|
if #user.update_attributes(params[:user])
flash[:notice] = "User #{#user.first_name} #{#user.last_name} was updated successfully."
format.html { redirect_to(:action => 'index') }
else
format.html { render :action => "edit" }
end
end
end
# DELETE /users/1
# DELETE /users/1.xml
def destroy
#user = User.find(params[:id])
#user.destroy
respond_to do |format|
format.html { redirect_to(admin_users_url) }
end
end
end
Namespace Routes
namespace 'admin' do
get 'admin' => 'manage#index'
resources :users
end
User Form
<%= form_for(#user, :url => admin_users_path(#user)) do |f| %>
<% if #user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% #user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :username %><br />
<%= f.text_field :username %>
</div>
<div class="field">
<%= f.label :first_name %><br />
<%= f.text_field :first_name %>
</div>
<div class="field">
<%= f.label :last_name %><br />
<%= f.text_field :last_name %>
</div>
<div class="field">
<%= f.label :salutation %><br />
<%= f.text_field :salutation %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, 'Confirm Password' %><br />
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Yes, you need attr_accessor :password and you don't need attr_accessor :password_confirmation as validates_confirmation_of :password will create it for you.

Resources