title: Rails 4 how to create and listing in the same page
body: <p>I have a model product and I want to create and then list under the text_field</p>
  
  <p>in my controller</p>
  
  <pre><code>class ProductController &lt; ApplicationController
  def buy
      @product = Product.new(product_params)
  
          respond_to do |format|
              if @product.save
                  format.html { redirect_to @product, notice: 'Product was successfully added.'}
              else
                  format.html { redirect_to @product, notice: 'Failed to added.'}
              end
          end
      end
  
      private
  
      def product_params
          params.permit(:name, :description)
      end
  </code></pre>
  
  <p>end</p>
  
  <p>and view </p>
  
  <pre><code>&lt;%= simple_form_for @product, :url =&gt; { :controller =&gt; 'product', :action =&gt; 'buy'} do |f| %&gt;
  &lt;%= f.input :name %&gt;
  &lt;%= f.input :description %&gt;
  &lt;%= f.button :label =&gt; 'BUY', :class =&gt; 'btn add-product btn-primary' %&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>and I try to list in the same view</p>
  
  <pre><code>        &lt;% @products.each do |product| %&gt;
          &lt;%= product.name %&gt;
          &lt;%= product.description %&gt;
  </code></pre>
  
  <p>and script</p>
  
  <pre><code>&lt;script&gt;
   $('.add-product').click(function(){
    $('.product').clone().first().appendTo('.container');
   })
  </code></pre>
  
  <p>I'm not sure the code can be run or not 
  Cuz I got a problem with </p>
  
  <p>undefined method `model_name' for NilClass:Class </p>
  
  <p>in this   &lt;%= simple_form_for @product, :url => { :controller => 'product', :action => 'buy'} do |f| %></p>
  
  <p>my question is like <a href="https://stackoverflow.com/questions/14483722/append-form-partial-in-the-new-view-of-the-same-model-in-rails">Append form partial in the new view of the same model in rails</a>
  but I can't use   %input{:name => "model[][name]"} to be my input</p>
  
  <p>Can help me how to fix my code
   thanks~</p>
  
  <p></p>