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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:08:36+00:00 2026-06-17T05:08:36+00:00

I’m working on the Rails guide now and am confused about the controller and

  • 0

I’m working on the Rails guide now and am confused about the controller and scaffold. In the guide I saw two commands:

$ rails generate controller home index
$ rails generate scaffold Post name:string title:string content:text

I know the first line means it creates a home controller with an action index. However, I don’t quite understand what the practical meaning is here. Does it simply mean it will render a page with an address “home/index”?

For the second line, what I understand is it creates an app called Post with three parameters name, title, and content. I don’t know if it is correct and am wondering what scaffold actually means. The guide’s explanation is a bit ambiguous to me.

Thanks.

  • 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-06-17T05:08:38+00:00Added an answer on June 17, 2026 at 5:08 am

    So, first, you should just run them. They’ll list the files they create and you can look at them.

    The first one creates a controller named home (a piece of code for responding to web requests) with one action named index. An action is the combination of ant HTTP verb and a URL (in this case GET /home/index) that corresponds to a method in the controller. The generator also creates a dummy view for rendering that action, and some empty test and helper files. You can see that in what it prints:

      create  app/controllers/home_controller.rb
       route  get "home/index"
      invoke  erb
      create    app/views/home
      create    app/views/home/index.html.erb
      invoke  test_unit
      create    test/functional/home_controller_test.rb
      invoke  helper
      create    app/helpers/home_helper.rb
      invoke    test_unit
      create      test/unit/helpers/home_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/home.js.coffee
      invoke    scss
      create      app/assets/stylesheets/home.css.scss
    

    Particularly useful is the controller:

    class HomeController < ApplicationController
      def index
      end
    end
    

    You haven’t given Rails any information about what you want that action to do (you just said, “create a controller called ‘home’ with some action called ‘index'”), so it’s up to you to fill out that method. And you can see the URL info by invoking rake routes:

    home_index GET /home/index(.:format) home#index
    

    In other words, when you send a GET request to /home/index it calls HomeController#index. Since that method is empty and doesn’t tell Rails what to render, it will default to rendering the view at app/views/home/index.html.erb, which the generator also created and expects you to do something interesting with.

    The second generator does a lot more. It creates a resource, which means a model that you store in the database and also a controller with simple CRUD actions and dummy views to manipulate that model. So in addition to the controller/view stuff above, it also creates an upgrade script to create the right table in the DB and a Ruby class that will serve as the model. Look particularly at the first two “create” items here, and load them up in your editor:

      invoke  active_record
      create    db/migrate/20130111151206_create_posts.rb
      create    app/models/post.rb
      invoke    test_unit
      create      test/unit/post_test.rb
      create      test/fixtures/posts.yml
      invoke  resource_route
       route    resources :posts
      invoke  scaffold_controller
      create    app/controllers/posts_controller.rb
      invoke    erb
      create      app/views/posts
      create      app/views/posts/index.html.erb
      create      app/views/posts/edit.html.erb
      create      app/views/posts/show.html.erb
      create      app/views/posts/new.html.erb
      create      app/views/posts/_form.html.erb
      invoke    test_unit
      create      test/functional/posts_controller_test.rb
      invoke    helper
      create      app/helpers/posts_helper.rb
      invoke      test_unit
      create        test/unit/helpers/posts_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/posts.js.coffee
      invoke    scss
      create      app/assets/stylesheets/posts.css.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.css.scss
    

    You can see all the actions you can actually do, again by running rake routes:

         posts GET    /posts(.:format)          posts#index
               POST   /posts(.:format)          posts#create
      new_post GET    /posts/new(.:format)      posts#new
     edit_post GET    /posts/:id/edit(.:format) posts#edit
          post GET    /posts/:id(.:format)      posts#show
               PUT    /posts/:id(.:format)      posts#update
               DELETE /posts/:id(.:format)      posts#destroy
    

    Finally, check out the controller code at app/controllers/PostsController.rb to see what these actions actually do (they’re a bit more interesting).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am confused How to use looping for Json response Array in another Array.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.