lundi 16 mars 2015

Undefined method error for a variable in rails

i am developing an application where a user can post an issue and can comment on it.


the code for the issues/show.html.erb is



<h1><%=@issue.title%></h1><br />
<h3><%=@issue.content%></h3><br />



<%= link_to "Edit ", :controller => 'issues', :action => 'edit', :id => @issue.id %>



<h2>Comments</h2>

<%= render @issue.comments %>

<br />
<br />
<br />
<br />

<%= simple_form_for [@issue, Comment.new] do |f| %>
<%= f.label :content %><br />
<%= f.input :content %>
<%= f.submit "comment"%>
<%end%>


and the code for the comment controller is



class CommentsController < ApplicationController


def create
@issue = Issue.find(params[:issue_id])
@comment = @issue.comments.create(comment_params)

if @comment.save
redirect_to :controller => 'issues', :action => 'show'
else
render 'new'
end
end





private
def comment_params
params.require(:comment).permit(:content)

end


end


and the code for the comments partial is



<%= @comment.content%>


On running this code, rails is throwing an error - undefined method content, whereas content is the name of a column in my application PLease help


Aucun commentaire:

Enregistrer un commentaire