在我的tickets.js.coffee
:
$.ajax '/comments/add',
type: 'POST',
dataType: 'html'
success: ( data ) ->
alert 'success'
<%= form_for @comment, :url => user_ticket_message_comments_path( @user, @ticket, m ), :html => { :class => "add-comment", :id => "add-comment-" + @ticket.id.to_s } do |f| %>
<%= f.label :body, "Add comment" %>
<%= f.text_area :body %>
<%= f.hidden_field :message_id, :value => m.id %>
<%= f.submit "Add comment" %>
<% end %>
评论表:
id | message_id | body
----------------------
评论控制器:
def create
@comment = params[:comment]
@comment.save
end
我的路线.rb:
resources :messages do
resources :comments
end
我收到此错误:
undefined method `save' for {"body"=>"awef", "message_id"=>"15"}:ActiveSupport::HashWithIndifferentAccess
评论属于一条消息,消息有很多评论。
我应该在哪里解决这个错误?