lundi 22 mai 2017

Rails Setup act as commentable gem

after setting the gem everything is working greatly but after post the user comment did save in db someone know why?

the db

Comment id: 12, title: "", comment: nil, commentable_id: 36, commentable_type: "Dispute", user_id: 12, created_at: "2017-05-21 05:27:42", updated_at: "2017-05-21 05:27:42"

dispute controller


 def show
    @dispute = @order.dispute
    @comments = @dispute.comments.all

@comment = @dispute.comments.build(params[:comment])
    @comment.user = current_user
  end

dispite show view

<%= form_for [ @dispute, @comment], :url =>  order_dispute_comments_path  do |f|-%>
  <%= f.text_area :comment %>
  <%= f.submit "Post", :class => "btn_green" %>
<% end -%>




routes

   resources :orders  do 
     resource :dispute do
     resources :comments
   end
end

comments controller

def create
 # @dispute = @dispute.find params[:dispute_id]
    @order = Order.find(params[:order_id])
  @dispute = @order.dispute
  @comment = @dispute.comments.new params[:comment]
  @comment.user = current_user

  if @comment.save
   redirect_to order_dispute_path
  end
end
end

Aucun commentaire:

Enregistrer un commentaire