Reputation: 1123
In short, I've just migrated a comments scaffold to the app. The goal is to have comments displayed in the show action of a song. It's simple, I have a songs model, a comments model, and a user model. The user can upload songs -- and I'd like the user to be able to add comments to the songs. Unfortunately, I've been hit with the below error. I've looked into various solutions to no avail.
error msg:
ArgumentError in Songs#show
Showing /Users/apane/Downloads/leap/app/views/comments/_form.html.erb where line #1 raised:
First argument in form cannot contain nil or be empty
<%= form_for @comment do |f| %>
<% if @comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
See the github below -- I feel this is the most efficient way for troubleshooting as it's pretty easy to browse to the appropriate directories quickly.
www.github.com/apane/leap
Upvotes: 3
Views: 5519
Reputation: 11421
You are showing this form in show action of songs controller, and it has to be like this:
def show
@comment = Comment.new
end
Or in your form
<%= form_for Comment.new do |f| %>
Upvotes: 5