Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5957873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:27:47+00:00 2026-05-22T18:27:47+00:00

I have a user registration where a user sets his username, first_class and some

  • 0

I have a user registration where a user sets his username, first_class and some other attribs. Now, there are also some other attributes that i have to set, like :str or :acc.

These attributes would probably be set in a mass assignment command like create. I would not want to do something like update_attribute on each one separately of course. Therefore, i have to make them attr_accessible.

However, i don’t want the user to set them. For instance, if the user decides to have a first_class = ‘Ranger’, i would set his :str and and not him.

My idea is that i would just save params[:first_class] or params[:username] and just explicitly set everything else in my create method for the user. Is that how you would do it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:27:48+00:00Added an answer on May 22, 2026 at 6:27 pm

    I’m guessing that the other attributes are pre-determined based on what the user selects as part of the registration process?

    In that case, I’d add a before_create hook to your model that calculates and assigns those attributes accordingly:

    class PlayerCharacter < ActiveRecord::Base
      before_create :assign_attributes
    
      # ...
    
      # This is called after you call "update_attributes" but before 
      # the record is persisted in the database
      def assign_attributes
    
        # Stats are determined by the 'first_class' attribute
        stats = case first_class
          when "Ranger"  then { :str => 20, :dex => 19, :wis => 8 }
          when "Wizard"  then { :str => 10, :dex => 14, :wis => 18 }
        end
    
        self.attributes.merge!(stats)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such view that handles user registration. After creating new user i want
I have a product registration form that allows the user to add additional product
I have a user registration form that has a password and confirm password field.
I have a simple user registration page in my rails app that has two
I have made customized user registration page. and i have made that on theme
I'm building Rails application and I want to have user registration/login functionality. I also
I have working user registration form. It consist of Zend Form Elements. Now I
In my user registration routine, i have this code : @user = User.new(attribs) @user.build_inventory(:max_slots
Is there any module that can ask upon user registration so that the user
I am using ASP.net(2.0) with VB.NET. I have a User registration form. On that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.