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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:09:38+00:00 2026-06-16T21:09:38+00:00

I am studying the ruby on rails guides namely, the layouts and rendering topic

  • 0

I am studying the ruby on rails guides namely, the “layouts and rendering” topic at http://guides.rubyonrails.org/layouts_and_rendering.html

I am confused about passing an instance variable to a redirect_to method. How is this possible? I thought redirect_to would be relevant for redirecting to another webpage or a url.

In the examples given on the guide it says the following:

2.2.2 Rendering an Action’s View

If you want to render the view that corresponds to a different action
within the same template, you can use render with the name of the
view:

def update
  @book = Book.find(params[:id])
  if @book.update_attributes(params[:book])
    redirect_to(@book)
  else
    render "edit"
  end
end

The render “edit” makes complete sense, its going to render that new form again. But what in the world is going on with redirect_to(@book)? What exactly is that going to render and how is a book object going to be redirected to? BTW, the book model has columns, Name, author, pages etc…

  • 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-16T21:09:39+00:00Added an answer on June 16, 2026 at 9:09 pm

    redirect_to documentation

    redirect_to(options = {}, response_status = {}) Redirects the
    browser to the target specified in options.
    Record – The URL will be generated by calling
    url_for with the options, which will reference a named URL for that
    record.

    So when one does redirect_to(@book) @book is a specific record with an id .

    Thus, the associated records (in this case @book) show method is used as a template.

    In addition to above, if you look at the routes.rb file which defines these paths you will notice

    resources :books
    

    Now this route is essentially translated as (you can see by running rake routes)

        books GET    /books(.:format)                   books#index
              POST   /books(.:format)                   books#create
     new_book GET    /books/new(.:format)               books#new
    edit_book GET    /books/:id/edit(.:format)          books#edit
         book GET    /books/:id(.:format)               books#show
              PUT    /books/:id(.:format)               books#update
              DELETE /books/:id(.:format)               books#destroy
    

    Notice the book GET /books/:id books#show – which gets matched when you do redirect_to(@book)

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

Sidebar

Related Questions

Studying at http://ruby.railstutorial.org/ version 3.2 Stucked in the end of 6.2.1 section with the
I am studying Ruby on rails by Michael Hartl. I am stuck at the
After studying ruby for about a month, I decided to move on to Sinatra.
I've been studying Ruby on Rails for a class project. I keep hearing everything
I am new to using Github. I am studying Ruby on Rails with a
I'm currently studying regex (using ruby) and I would like to find the first
I've been studying fibers in Ruby, and the term semicoroutine has come up. What
While studying about JMX, I have seen one of the important feature of it
I'm studying Ruby and my brain just froze. In the following code, how would
Im studying some ruby code and I see this varx variable being used with

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.