Note that there are some explanatory texts on larger screens.

plurals
  1. POA blog using Bootstrap and Ruby on rails
    primarykey
    data
    text
    <p>I've been stuck for a time now with my commenting system on my blog. I now need you help to solv the problem and push me in the right direction. I'm using Ruby on rails and the twitter open source framework bootstrap.</p> <p><strong>show.html.erb:</strong></p> <pre><code> &lt;h2&gt;Comments&lt;/h2&gt; &lt;div id="comments"&gt; &lt;%= render :partial =&gt; @post.comments %&gt; &lt;/div&gt; &lt;%= form_for {@post, Comment.new} do |f| %&gt; &lt;p&gt; &lt;%= f.label :body, "New comment" %&gt;&lt;br/&gt; &lt;%= f.text_area :body %&gt; &lt;/p&gt; &lt;p&gt;&lt;%= f.submit "Add comment" %&gt;&lt;/p&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre> <p><strong>CommentsController:</strong></p> <pre><code>class CommentsController &lt; ApplicationController def create @post = Post.find(params[:post_id]) @comment = @post.comments.create!(params[:comment]) redirect_to @post end end </code></pre> <p><strong>Routes.rb</strong></p> <pre><code>Blog2::Application.routes.draw do resources :posts do resources :comments, :only =&gt; [:create] end </code></pre> <p><strong>comment.html.erb</strong></p> <pre><code>&lt;%= div_for comment do %&gt; &lt;p&gt; &lt;strong&gt; Posted &lt;%= time_ago_in_words(comment.created_at) %&gt; ago &lt;/strong&gt; &lt;br/&gt; &lt;%= comment.body %&gt; &lt;/p&gt; &lt;% end %&gt; </code></pre> <p><strong>model/ comment.rb</strong></p> <pre><code>class Comment &lt; ActiveRecord::Base belongs_to :post attr_accessible :body end </code></pre> <p><strong>I'm getting errors in show.html.erb for my two (:body) symbols and the form_for line.</strong></p> <p>Well this is my first blog and I'm pretty new to RoR, appreciate some help :) </p> <p><strong>1st Error:</strong></p> <pre><code> SyntaxError in Posts#show Showing /Users/Jdartland/blog_2/app/views/posts/show.html.erb where line #23 raised: /Users/Jdartland/blog_2/app/views/posts/show.html.erb:23: syntax error, unexpected '}', expecting tCOLON2 or '[' or '.' ... form_for {@post, Comment.new} do |f| @output_buffer.safe_c... ... ^ /Users/Jdartland/blog_2/app/views/posts/show.html.erb:29: syntax error, unexpected keyword_end, expecting '}' '); end ^ /Users/Jdartland/blog_2/app/views/posts/show.html.erb:32: syntax error, unexpected keyword_ensure, expecting '}' /Users/Jdartland/blog_2/app/views/posts/show.html.erb:34: syntax error, unexpected keyword_end, expecting '}' Extracted source (around line #23): 20: &lt;%= render :partial =&gt; @post.comments %&gt; 21: &lt;/div&gt; 22: 23: &lt;%= form_for {@post, Comment.new} do |f| %&gt; 24: &lt;p&gt; 25: &lt;%= f.label :body, "New comment" %&gt;&lt;br/&gt; 26: &lt;%= f.text_area :body %&gt; Trace of template inclusion: app/views/posts/show.html.erb Rails.root: /Users/Jdartland/blog_2 </code></pre> <p><strong>2nd Error</strong></p> <pre><code>ArgumentError in Posts#show Showing /Users/Jdartland/blog_2/app/views/posts/show.html.erb where line #23 raised: wrong number of arguments (1 for 0) Extracted source (around line #23): 20: &lt;%= render :partial =&gt; @post.comments %&gt; 21: &lt;/div&gt; 22: 23: &lt;%= form_for @post, Comment.new do |f| %&gt; 24: &lt;p&gt; 25: &lt;%= f.label :body, "New comment" %&gt;&lt;br/&gt; 26: &lt;%= f.text_area :body %&gt; Rails.root: /Users/Jdartland/blog_2 Application Trace | Framework Trace | Full Trace app/views/posts/show.html.erb:23:in `_app_views_posts_show_html_erb___3910729666325401247_70293324213060' app/controllers/posts_controller.rb:26:in `show' Request Parameters: {"id"=&gt;"2"} </code></pre> <p><strong>After following zeantsoi's advice I changed the show.html.erb and _comment.html.erb. This is where I am left with right now 15/6 22.03</strong> <em><strong>UPDATED!</em></strong></p> <p>Updated show.html.erb:</p> <pre><code>&lt;h2&gt;Comments&lt;/h2&gt; &lt;div id="comments"&gt;s &lt;%= render :partial =&gt; 'posts/comment', :locals =&gt; {:comments =&gt; @post.comments} %&gt; &lt;p&gt; &lt;/div&gt; &lt;/div&gt; &lt;%= form_for [@post, Comment.new] do |f| %&gt; &lt;p&gt; &lt;%= f.label :body, "New comment" %&gt;&lt;br/&gt; &lt;%= f.text_area :body %&gt; &lt;%= f.submit "Add comment" %&gt; &lt;/p&gt; &lt;% end %&gt; </code></pre> <p><strong>The current Error:</strong></p> <pre><code>howing /Users/Jdartland/blog_2/app/views/posts/show.html.erb where line #28 raised: undefined method `body' for #&lt;Comment:0x007f88611a1738&gt; Extracted source (around line #28): 25: &lt;%= form_for [@post, Comment.new] do |f| %&gt; 26: &lt;p&gt; 27: &lt;%= f.label :body, "New comment" %&gt;&lt;br/&gt; 28: &lt;%= f.text_area :body %&gt; 29: 30: &lt;%= f.submit "Add comment" %&gt; 31: &lt;/p&gt; Rails.root: /Users/Jdartland/blog_2 Application Trace | Framework Trace | Full Trace app/views/posts/show.html.erb:28:in `block in _app_views_posts_show_html_erb___3992012847724603598_70111860057680' app/views/posts/show.html.erb:25:in `_app_views_posts_show_html_erb___3992012847724603598_70111860057680' app/controllers/posts_controller.rb:26:in `show' </code></pre>
    singulars
    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.
 

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