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

  • Home
  • SEARCH
  • 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 6944103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:14:33+00:00 2026-05-27T13:14:33+00:00

I have a simple user table and i would like to add a new

  • 0

I have a simple user table and i would like to add a new field to my user table that says permalink. This permalink would be updated with the following code for all the users
name.downcase.gsub(/[^0-9a-z]+/, ' ').strip.gsub(' ', '-'). I want to create a migration file that updates all the users permalink fields with the code above so that old users would have their permalink set and i would use an after_create method for new users.

  • 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-27T13:14:34+00:00Added an answer on May 27, 2026 at 1:14 pm

    I think you could try something like this:

    class User < ActiveRecord::Base
    
      before_create :set_permalink
    
      def set_permalink
        permalink = name.downcase.gsub(/[^0-9a-z]+/, ' ').strip.gsub(' ', '-') 
      end
    end
    

    This actually uses the before_create callback, which would address the deriving of the permalink field for new users. I think this is what you actually need.

    And in your migration file …

    class UpdateUsersPermalink < ActiveRecord::Migration
    
      def self.up
        User.reset_column_information
        User.all.each do |u|
          if u.permalink.nil?
            u.set_permalink
            u.save!
          end
        end
      end
    
      ...
    end
    

    .. which would take care of any existing Users that do not have this field set just yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple social network project going and I would like to add
I have a simple table view which is editable. All I need the user
I have frequent updates to a user table that simply sets the last seen
I have a sample file like the following: CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11 (
This is driving me crazy. I have a very simple user control: public int?
I have a simple Desktop Facebook application that allows the user to retrieve some
I have a VERY simple windows form that the user uses to manage Stores.
I have a User entity which represents a User table in my database. This
I have a simple user signup form with a checkbox that lets users get
I'm trying to do something simple like this: members = models.ManyToManyField(User, blank=True, null=True, unique=True)

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.