Hello,
I am having a bit of trouble with my rails application. It short, its a social networking app where users have a profile, have submissions, and can comment on submissions.
My routes are as follows:
map.connect '/:username', :controller => 'users', :action => 'show'
map.connect '/:username/:id', :controller => 'submissions', :action => 'show'
So when they are viewing a submission the URL looks something like:
The number is the id number of the category. So far so good. Where I am running into trouble is when I try to submit a comment on the submission. There is a form for submitting comments on each submission page that looks like this:
<% form_for Comment.new do |f| %>
<%= f.text_area :message %>
<%= f.submit "Submit", :disable_with => 'Submitting...' %>
<% end %>
and the controller looks like this:
def create
submission = Submission.find(params[:id])
comment = cat.comments.create(params[:comment])
comment.created_at = Time.now
comment.save
redirect_to submission
end
Now every time I try to make a comment submission Rails returns:
ActiveRecord::RecordNotFound in CommentsController#create Couldn't find Submission without an ID or undefined method `answers' for nil:NilClass
Basically rails isn't pulling the :id from the URL with params and I don't know why. The submission page displays correctly for each ID in the URL, so I don't get why its not pulling it for this form. If I name the id explicitly (IE Submission.find(2345)) it works perfectly...so what am I missing? Am I just being stupid?
My relationships are set up properly as well.
Thanks in advance.