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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:35:07+00:00 2026-05-16T23:35:07+00:00

If an action looks like: def show @post = Post.find(params[:id]) end I can then

  • 0

If an action looks like:

def show
  @post = Post.find(params[:id])
end

I can then do:

<%= @post.title %>

How does it pass the object to the view?

Since my action has only one line, what programming technique or pattern is used to take the @post object and pass it to the view (template) page?

I know it assumes the view will be the same name as the action, but how does it do this?

  • 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-16T23:35:08+00:00Added an answer on May 16, 2026 at 11:35 pm

    for example like this:
    we will transfer MyController variables to MyView variables

    class MyController
        def my_action
            @my_variable = 100
        end
    end
    
    class MyView
        def process_view_with_variables(variables)
            puts variables.inspect # => [{"@my_variable"=>100}]
            variables.each do |var|
                var.each {|name,value| self.instance_variable_set(name,value)}
            end 
            puts self.instance_variables # => @my_variable
            # .. view_rendering here
        end
    end
    
    # create new view and controller instances
    my_controller = MyController.new
    my_view = MyView.new
    
    # call my_action method in MyController instance (which will initialized some variables)
    my_controller.my_action
    
    # let know about instance variables in our controller
    puts my_controller.instance_variables.inspect # => ["@my_variable"]
    
    # simple array, for store variables (this is like a proxy)
    controller_variables = []
    
    # transfer instance variables from controller to proxe
    my_controller.instance_variables.each do |variable|
        controller_variables << {variable => my_controller.instance_variable_get(variable)}
    end
    
    # let know which instance variables bow in proxy array
    puts controller_variables.inspect # => [{"@my_variable"=>100}]
    
    # call method process_view_with_variables which will transfer variables from proxy to view
    my_view.process_view_with_variables(controller_variables) # => [{"@my_variable"=>100}]#
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If your controller action looks like this: respond_to do |format| format.html { raise 'Unsupported'
My route looks like: routes.Add(new Route({companyName}/{action}/{id}, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new {
I want to have a route that looks something like: www.abc.com/companyName/Controller/Action/Id However, all the
I have an a4j:commandButton which looks like this <a4j:commandButton id=stopBtn type=button reRender=lastOp action=#{MyBacking.stop} value=Stop
I have an action called 'list' and is defined like def list @subjects =
I would like to render the show action of a user , from another
I'm using a filter to log exceptions thrown by actions which looks like this:
Normally my URLs look like the standard: www.example.com/controller/action Now I want to setup my
My action listener on a JComboBox invokes a thread. I would like the component
I have a jQuery post submitting a form to a controller create action, which

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.