Home>

I have a question about passing passwords using the wizard screen in Ruby on Rails.

Occurrence

I'm trying to move to the next screen by pressing create_companies, but I get the following error:
"Undefined method` []'for nil: NilClass " I understand that i am told that your password is empty

If i stop the part in the two lines of def create_companies in the code with binding.pry "password" =>"cccccc3" I was able to confirm that the password has changed from the previous page

I'm wondering if it's a method to take out the transitioned password again and give it as described below, but I would appreciate it if you could teach me a specific method for that.

code
def create
    @user = User.new (sign_up_params)
      unless @ user.valid?
        render: new and return
      end
    session ['devise.regist_data'] = {user: @ user.attributes}
    session ['devise.regist_data'] [: user] ['password'] = params [: user] [: password]
    @company = @ user.build_company
    render: new_companies
  end
  def create_companies
    @user = User.new (session ['devise.regist_data'] ['user'])
    binding.pry
    @company = Company.new (company_params)
      unless @ company.valid?
        render: new_companies and return
      end
    session ['devise.regist_data'] = {user: @ user.attributes, company: @ company.attributes}
    session ['devise.regist_data'] [: company] [: user] ['password'] = params [: company] [: user] [: password]
    @company_detail = @ user.build_company_detail
    render: new_company_details
  end
  • Answer # 1

    The problem was that the page corresponding to def create_companies did not have the information of [: user] [: password] pointed to by params.

    I'm sorry for the short question

    I solved it with this description

    def create
        @user = User.new (sign_up_params)
          unless @ user.valid?
            render: new and return
          end
        session ['devise.regist_data'] = {user: @ user.attributes}
        session ['devise.regist_data'] [: user] ['password'] = params [: user] [: password]
        @company = @ user.build_company
        render: new_companies
      end
      def create_companies
        @user = User.new (session ['devise.regist_data'] ['user'])
        @company = Company.new (company_params)
          unless @ company.valid?
            render: new_companies and return
          end
        session ['devise.regist_data'] = {user: @ user.attributes, company: @ company.attributes}
        session ['devise.regist_data'] [: company] = params [: company]
        @company_detail = @ user.build_company_detail
        render: new_companies_details
      end