gem 'acts_as_commentable'
rails g comment
rake db:migrate
1.新增 CommentsController
class CommentsController < ApplicationControllerdef create@link = Link.find(params[:link_id])comment = Comment.new( :title => "", :comment => params[:comment][:comment])if current_user != nilcomment.user_id = current_user.idendlogger << params[:comment]@link.add_comment commentredirect_to root_pathendend
:comment => params[:comment][:comment]) 這邊這樣用是因為 view 用simple_form_for 後來帶過來的是 comment={comment={msg}} 之後再研究看看正常寫法
2. view
<%= simple_form_for(@comment, :url => comments_path(@comment, :link_id => link )) do |f| %><div><%= f.input :comment , :label => "--" %><%= f.button :submit , :class => "btn btn-info"%></div><% end %>
沒有留言:
張貼留言