Note that there are some explanatory texts on larger screens.

plurals
  1. PO2 instance variables of the same name in different controllers
    primarykey
    data
    text
    <p>I finished Michael Hartl's Ruby on Rails Tutorial. Now I'm working on the suggested exercises. The application he builds is basically a Twitter clone where one can post Microposts and they appear in your feed <a href="http://ruby.railstutorial.org/chapters/user-microposts#fig-micropost_created" rel="nofollow">http://ruby.railstutorial.org/chapters/user-microposts#fig-micropost_created</a></p> <p>The main page is in <code>home.html.erb</code> from the StaticPagesController and features a Micropost textbox where one can post Microposts. The code for the textbox looks like so:</p> <pre><code>&lt;%= form_for(@micropost) do |f| %&gt; &lt;%= render 'shared/error_messages', object: f.object %&gt; &lt;div class="field"&gt; &lt;%= f.text_area :content, placeholder: "Compose new micropost..." %&gt; &lt;/div&gt; &lt;%= f.submit "Post", class: "btn btn-large btn-primary" %&gt; &lt;% end %&gt; </code></pre> <p>The <code>@micropost</code> variable is initialized in the StaticPagesController like so:</p> <pre><code>class StaticPagesController &lt; ApplicationController def home if signed_in? @micropost = current_user.microposts.build end end </code></pre> <p>Now inside the MicropostsController there's a create action like so:</p> <pre><code>def create @micropost = current_user.microposts.build(params[:micropost]) if @micropost.save flash[:success] = "Micropost created!" redirect_to root_url else @feed_items = [] render 'static_pages/home' end end </code></pre> <p>My question is what is the purpose of the first @micropost variable as opposed to the second?</p> <p>thanks, mike</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload