ruby on rails - How do I set up the proper routes for an acts_as_commentable form? -
there 2 models: user
, commenting (provided devise), , audio
, comment on. each audios#show
page should list comments audio, , have little form through submit one.
i made audio
acts_as_commentable
. made sure comment belongs_to :user
, , user
has_many :comments
.
for routes, have
resources :audios resources :comments end
then, on audios_controller,
def show if user_signed_in? @comment = @audio.comments.new end end
then wrote simple form_for(@comment)
form 'comment' field , submit button. that's it.
the error upon loading page undefined method 'comments_path'. googled error, read stackoverflow responses, , tried form_for(@audio, @comment)
instead. gets error **can't write unknown attribute 'html'`.
i'm little stumped; i've got models , relationships sketched out on notepad i'm inexperienced , use of things don't understand, devise behind scenes, throwing me loop. if give me tip on these routes/forms love it.
in routes.rb need have this:
# routes.rb resources :comments, :only => [:create, :destroy]
the :comments
route goes alone, outside resource trying add comment ability.
then, if run rake routes
return:
$ rake routes comments post /comments(.:format) comments#create comment delete /comments/:id(.:format) comments#destroy
this give comments_path
helper , comment_path(:id)
helper complete post , delete requests.
check tutorial, helped me lot when needed use gem: http://twocentstudios.com/blog/2012/11/15/simple-ajax-comments-with-rails/
Comments
Post a Comment