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 3353632
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:10:30+00:00 2026-05-18T02:10:30+00:00

The command rails generate scaffold Post name:string title:string content:text generated the following 20101109001203_create_posts.rb file:

  • 0

The command

rails generate scaffold Post name:string title:string content:text

generated the following 20101109001203_create_posts.rb file:

class CreatePosts < ActiveRecord::Migration
  def self.up
    create_table :posts do |t|
      t.string :name
      t.string :title
      t.text :content

      t.timestamps
    end
  end

  def self.down
    drop_table :posts
  end
end

Since I’m new to Ruby (just read one book), I have some questions on this block of code:

  1. What does self. means in self.up and self.down ? How it differs from simply up and down ?

  2. What does all these colons (:) means in :posts, :name, etc. ? Is that just a part of the variable name ?

  3. What does t.string :name means ? Is that a call to string function on object t with parameter :name ?

Thanks a lot!!

  • 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-18T02:10:30+00:00Added an answer on May 18, 2026 at 2:10 am
    1. If you define a method using def foo, you’re creating an instance method called foo. I.e. if you have an instance of class CreatePosts you can do the_instance.foo. However by doing def self.foo (or alternatively def CreatePosts.foo which does the same thing, because self == CreatePosts in the class ... end-block), you’re defining a singleton method which is only available on CreatePosts itself. I.e. it is called as CreatePosts.foo not the_instance.foo (this is somewhat similar to static methods in other languages, but not quite because you can use the same syntax to define singleton methods on objects that aren’t classes).

    2. :name has nothing to do with any variable called name. It’s a symbol literal, which is kind of like an interned immutable string (though the Symbol class does not define any methods for string-manipulation). You can think of symbols as some sort of mini-strings which are used when you just need to label something and don’t need to do string manipulation.

    3. Yes, exactly.

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

Sidebar

Related Questions

I ran the following commands: rails generate scaffold order name:string address:text email:string pay_type:string rails
This CURD generated by scaffold method using following command rails g scaffold contact fullname:string
I'm new to rails and was trying out the scaffold command - the following
I'm using this command: rails generate model DayOfMonth day:integer Rails generated the model DayOfMonth
I try to create a standalone migration file by executing the following command: rails
Running the command generates new rails projects: $ rails generate controller home index The
when i give the command rails s following error comes please help me! still
I have this command in a Rails controller open(source) { |s| content = s.read
I just issued a [ script/generate scaffold User ] command to generate my files.
As the title says, how can i generate the default mongoid.yml config file on

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.