On 19 Apr 2011, at 23:47, Neil Bye <[email protected]> wrote:
> Frederick Cheung wrote in post #993841: >> On Apr 19, 8:39pm, Neil Bye <[email protected]> wrote: >>> Tim Shaffer wrote in post #993815: >>> >> >> sounds to me like params[:id] isn't set. >> >> Fred > > Not sure what you mean. How would I set params[:id] ? Typically it will come from the form or the URL, but if you try and use it when it's not set, things will blow up. > > It works if I use params[:user_id] or [:current_user_id] > > Surely the pproblem is that it doesn't know which comment it is supposed > to be subcommenting on. That us precisely it - you're trying to create the subcomment on the comment fetched by params[:id], but params[:id] isn't set > > This is what calls it, is there a problem here. > > <%= form_for :subcomment, :remote => true, :url => > user_subcomments_path(@user) do |form| %> > <%= form.text_field :body %> > <p><%= submit_tag 'Comment' %></p> > <% end %> Yes - nothing in this form says which comment the newly created subcomment belongs to. In general you can either use a hidden_field with the id or make it part of the URL, eg as a nested resource (in which case params[:comment_id] would contain the correct value). I would normally have comment_subcomments_path(@comment) (assuming @comment is what the user wants to comment on) rather than user_subcomments_path(@user) with a hidden field with the comment_id because the user creating an object is usually obtainable via your login system (indeed in most cases you don't want people to be able to create subcomments as other users just by editing the URL the form posts to) Fred > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

