There are two classes of accounts in my application. I am trying to update the attributes of one of them (Investors). They are created using one form through the device. As a result, when an investor tries to update their account information, the form requires them to provide and confirm their password. I would like them to be able to edit (first name, last name, etc.) without entering a password if they do not want to change their password with these fields.
Here is my update method in investor controller
def update session[:investor_params] ||= {} session[:investor_params].deep_merge!(params[:investor]) if params[:investor].present? @investor.attributes = session[:investor_params] params[:investor_params].delete(:password) if params[:investor_params][:password].blank? params[:investor_params].delete(:password_confirmation) if params[:investor_params][:password_confirmation].blank? respond_to do |format| if @investor.update_attributes(params[:investor_params]) session[:investor_params] = nil sign_in(@investor.account, :bypass => true) format.html { redirect_to(projects_url, :notice => 'Investor was successfully updated.') } format.xml { render :xml => @investor, :status => :created, :location => @investor } else format.html { render :action => "edit", :layout => "investor" } format.xml { render :xml => @investor.errors, :status => :unprocessable_entity } end end end
Here is my registration controller
class RegistrationsController < Devise::RegistrationsController layout "index" protected def after_sign_up_path_for(resource) new_user_url(:account => resource) end end
Here are my .rb routes
devise_for :accounts, :controllers => { :registrations => 'registrations', :passwords => 'passwords', :sessions => 'sessions' } devise_scope :account do root :to => 'registrations#new'
And this is part of my investor model, which refers to the attributes for the account model.
class Investor < ActiveRecord::Base has_one :account, :as => :profile accepts_nested_attributes_for :account
Here is the part of the account model referenced
class Account < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me, :invited_by, :invited_by_id
I tried the guidelines for developing github repo, but I couldn't get it to work for me.
If you have any suggestions or if I have something missing, let me know!