I have an Issue model and a Comment model. On the issue#show view, I have a comment form. I create the @comment for the form in the issue#show controller action, and then pass it to the comment#create controller action to actually create and save the comment to the db. However, once the @comment params are passed to the comment#create action, I no longer have the issue_id information that I need. How would I pass that information? Here are my files:
<%= form_for @comment do |f| %>
<%= render 'comment_fields', :f => f %>
<%= f.submit "Submit" %>
<% end %>
issue controller:
def show
@issue = Issue.find(params[:id])
@votes = Votership.where(:issue_id => @issue.id)
@current_user_vote = @votes.where(:user_id => current_user.id).first
@comment = Comment.new
end
and the comment controller:
def create
@comment = Comment.new(params[:comment])
@comment.save
redirect_to :back
end
You just need to modify the way you create your
@commentin theshowactionNow when you render the form for
@comment, theissue_idshould be present in the hidden form inputsThis is unrelated to your question, but I’m also noticing the way you’re loading
@current_user_voteYou should probably do this as: