class CommentsController < ApplicationController
def create
@commentable= context_object()
@comment @commentable.comments.build(params[:comment].merge(:user_id
=>
current_user.id))
if @comment.save
respond_to do |format|
format.js
end
else
render :action => ''new''
end
end
private
def context_object
params[:constraint]
[:context_type].singularize.classify.constantize.find( context_id )
end
def context_id
params["#{ params[:constraint][:context_type].singularize }
_id"]
end
end
This commenting module has served me well but I ran into a hitch this
morning, possibly because of my use of nested resources. Essentially,
I now have a URL like:
/projects/3/albums/6/attachments/84
When I comment on that page, I get the error:
ActiveRecord::RecordNotFound (Couldn''t find Project without an
ID):
app/controllers/comments_controller.rb:102:in `context_object''
app/controllers/comments_controller.rb:14:in `create''
My routes file looks like:
resources :projects do
resources : albums do
resources :attachments
end
end
resources :attachments do
resources :comments, :only =>
[:create, :update,:destroy], :constraint => {:context_type =>
"conversations"}
end
Any ideas on how I can get the commenting module to play nicely with
commenting on `project>Album>Attachment ?`
Thanks for the input,
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.