title: CRUD of a model within another model
body: <p>I have Post CRUD. On show.html.erb for Post, I want CRUD for comment. I am using devise for User. I have tried what others have suggested elsewhere on stack overflow but it has not worked. It keeps saying @comment is empty. I'd appreciate your help. </p>
  
  <p>comments controller</p>
  
  <pre class="lang-rb prettyprint-override"><code>    def new
          @user = current_user
          @post = Post.find(params[:post_id])
          @comment = @post.comments.new
          render :template =&gt; 'posts/show'
      end
  
      def create
          @user = current_user
          @post = Post.find(params[:post_id])
          @comment = @post.comments.new(post_params)
          render :template =&gt; 'posts/show'
  
          if @comment.save
              redirect_to post_path(post.id), notice: "Success!~"
          else 
              redirect_to post_path(post.id), alert: "Failure!"
          end
  
      end
  
      private
          def comment_params
              params.require(:comment).permit(:text)
          end
  </code></pre>
  
  <p>show.html.erb (within posts folder)</p>
  
  <pre class="lang-rb prettyprint-override"><code>&lt;%= form_for([@user, @post, @comment]) do |form| %&gt;
    &lt;p&gt;
      &lt;%= form.text_area :text %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= form.submit %&gt;
    &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>