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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:35:26+00:00 2026-05-19T06:35:26+00:00

In Ryan Bates’s first episode on complex forms , he adds the following to

  • 0

In Ryan Bates’s first episode on complex forms, he adds the following to a model:

# models/project.rb
has_many :tasks

def task_attributes=(task_attributes)
  task_attributes.each do |attributes|
    tasks.build(attributes)
  end
end

I’ve never thought about this before, but how does the Project model know what “tasks” of which Project instance? Does that come from the has_many association? Is it like, when the project is running and I’m viewing a Project, that’s the “active” object so project.rb knows which Project object we’re referring to, so it knows that tasks is really some_current_project.tasks? (I’m obviously grasping at straws here.)

Also, if someone would point me to some reference that explains other questions like this one, I’d really appreciate it.

I hope my question is clear. Please ask for more clarification in comments if needed.

Please note: I know that Active Record handles CRUD actions and that objects correspond to rows in tables, etc. Those are just descriptions of what Active Record is. I’m looking for how it works when the project is running. I also now the constructs MVC, but I can’t seem to find a detailed explanation of what information is sent where with respect to Rails.

  • 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-19T06:35:28+00:00Added an answer on May 19, 2026 at 6:35 am

    (Not sure I fully understood your question, feel free to let me know if that’s the case.)

    A rails model is basically a ruby class that is persisted to a database. So it acts like a normal ruby object for the most part, with some database magic mixed in.

    You tell rails which project instance to load (e.g. by providing an id), and it loads the data from the database.

    Then, when you call project.tasks is when the magic happens: the Project model has no tasks method, so it will trigger ruby’s method_missing method. This will then load the associated records into model instances and provide access to them via a rails object.

    Since a project has many tasks, rails knows it should look into the tasks database and load the rows where project_id is equal to the project model’s id attribute.

    In short, ruby meta-programming and monkey patching possibilities make much of rails’ magic possible.


    (Edit for question on routing.)

    When you want to edit project number 13, you go to a URL that looks something like http://www.mysite.com/projects/13/edit. If you look at routes.rb in your config directory, you’ll see (in Rails3) resources :projects what Rails does is set up all sorts of paths for you. Behind the magic, the edit path looks like

    get '/projects/:id/edit' => 'projects#edit'
    

    This basically says “when a user wants to see http://www.mysite.com/projects/13/edit, send him to the edit action in the projects controller and set the id parameter to the value that’s in that place.

    Then in your controller, you’ll load the appropriate project with

    @project = Project.find(params[:id])
    

    In a similar way, you could do this (this is an dumb example):

    In routes.rb, put

    get '/projects/:id/edit_name/:name' => 'projects#edit'
    

    And then in you controller

    @project = Project.find(params[:id])
    @project.name = params[:name]
    

    So rails basically uses magic to assign values in the URL to params you can work with in your controller. You can read more about routing here: http://guides.rubyonrails.org/routing.html

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

Sidebar

Related Questions

I have cloned a rails project from Ryan Bates (complex forms samples) and am
We've all seen the brilliant complex forms railscast where Ryan Bates explains how to
Following Ryan Bates' instructions on creating a before_filter that sets a time_zone like so
I am following Ryan Bates railscasts I18n Internationalization and hitting a problem/question. I am
I'm trying to deploy to a VPS following Ryan Bates screencast. I'm using thin
I am trying to use Ryan Bates 'letter-opener' gem as described in Episode #104
I have created a new project using devise login according to Ryan Bates' railscast
I'm using jquery_token_input after following Ryan Bates railscast #258 and this is the code
I am following Ryan Bates' railcast 146 and it is really helpful. However, Im
I've been following through Ryan Bates' railscast on using cancan but am stumped as

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.