ruby on rails 4 - Can not save user sign up info when using devise and wicked -


im new rails platform...i have issue of saving user sign information on clicking register in form....i no error on checking rails console user information equated nil...cant figure out why. user steps controller code

class userstepscontroller < applicationcontroller include wicked::wizard  steps :finishing_step  def show  @user = current_user   render_wizard end  def update   @user = current_user   if @user.save    redirect_to root_path   else     render_wizard   end end  def user_params   params.require(:user).permit(:first_name, :middle_name, :last_name, :address_first_line, :address_second_line, :city, :nationality) end  private  def redirect_to_finish_wizard   redirect_to root_path, notice: "thanks signing up." end end 

below code users controller

class userscontroller < applicationcontroller def create @user = user.new(params[:user])       if @user.save         redirect_to root_path       else         render_wizard       end     end   end 

here below code simple form user sign information

<%= form_for user.new, url: wizard_path |f| %> <div><%= f.label :first_name, "first name" %><br />     <%= f.text_field :first_name %></div>   <div><%= f.label :middle_name, "middle name" %><br />     <%= f.text_field :middle_name %></div>   <div><%= f.label :last_name, "last name" %><br />     <%= f.text_field :last_name %></div>   <div><%= f.label :phone_number, "phone number" %><br />     <%= f.text_field :phone_number %></div>   <div><%= f.label :date_of_birth, "date of birth" %><br />     <%= f.date_select :date_of_birth, start_year: 1900 %></div>   <div><%= f.label :address_first_line, "address (first line)" %><br />     <%= f.text_field :address_first_line %></div>   <div><%= f.label :address_second_line, "address (second line)" %><br />     <%= f.text_field :address_second_line %></div>   <div><%= f.label :city, "city" %><br />     <%= f.text_field :city %></div>   <div><%= f.label :nationality, "nationality" %><br />     <%= country_select(:user, :nationality, {selected: "ug"}) %></div>     <div>     <%= f.label :avatar %>     <%= f.file_field :avatar %>   </div>   <div>     <%= f.label :terms_of_service, "agree terms of service" %> <br>     <%= f.check_box :terms_of_service %>   </div>   <%= f.submit "register", class: "btn btn-primary" %>   <% end %> 

for in advance

i think there mistakes in conception. wizard operates after sign_up of user. basically, need create user first without wizard.

  1. creation of user

if you're using devise model user, have user controller somewhere. actually, class userscontroller useless if using devise.

so if want redirect wizard step after sign up, need override devise registration controller (doc: redirect specific page). so, create new controller this:

class registrationscontroller < devise::registrationscontroller   protected    def after_sign_up_path_for(resource)     user_steps_path(:finishing_step) #add proper route   end end 

i don't have content of config/route.rb file need have :

resources :user_steps 
  1. adding steps

wicked wizard works this: - 1 controller 2 actions (show , update) - n views n steps (1 step = 1 view, 42 steps = 42 views)

you can access name of current step in actions show , update using step.

render_wizard render view of current step render_wizard @user render next step view (or current step view if there error)

  1. using strong parameters

in controller, never use user_params. in update action, never @user parameters form. current_user doesn't call user_params you.

also, there big difference between save , update_attributes , think want use second in update action.

it's better place user_params in private section also.

  1. final form of controller

your controller should guess:

  class userstepscontroller < applicationcontroller     include wicked::wizard      steps :finishing_step      def show       @user = current_user       render_wizard     end      def update       @user = current_user       if @user.update_attributes(user_params)         # because have 1 step, don't need render_wizard @user         redirect_to_finish_wizard       else         render_wizard       end     end      private      def user_params       params.require(:user).permit(:first_name, :middle_name, :last_name, :address_first_line, :address_second_line, :city, :nationality)     end      def redirect_to_finish_wizard       redirect_to root_path, notice: "thanks signing up."     end   end 
  1. read doc

i think miss tips in wicked doc. maybe should re-read it. wicked doc


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -