nathanvda/on_the_spot — Issue #34: Feature Request: Ability to add a new comment (nested resource)
Author: dleatham
Created: 2011-12-22 04:18:23+00:00
State: open

Very nice gem. I'm using it on my first Rails 3.1 project and it is working well. I'm an inexperienced coder and the ease of install/setup is very much appreciated.

Going outside the box of "editing in place", I tried to use this gem to create a "new comment" on a page where I'm showing a Post. In my models:
- Post
> has_many :comments
> accepts_nested_attributes_for :comments
-Comment
> belongs_to :post
> attr_accessible :body

In the :show action of my posts_controller.rb I created a new instance of :comment (@new_comment = @post.comments.new) and assigned the :body text to be: "Click here to add a comment...". In the show.html.erb file I added: <%= on_the_spot_edit @new_comment, :body %>

When I entered some text and click "OK" I got the error: "Couldn't find Comment without an ID" I'm assuming that the :update action cannot save a new instance. I'm guessing that if on_the_spot could be told to call the :create action, this might work, but I'm too inexperienced with Rails to know for sure.

I've found many approaches to adding a Comment to a page where I'm showing a Post, but they all seem to be overly complex. This is a common enough use-case, you may want to consider adding the ability for on_the_spot to create a new nested-resource record "in place." I'm sure it would be a popular addition. (Or if there is a way to accomplish this already, adding some documentation on the subject would be great.)