param丢失或值为空:会话

时间:2015-10-30 00:10:31

标签: ruby-on-rails parameters

这是此主题的后续内容:Ruby on Rails: found unpermitted parameters: _method, authenticity_token

我有以下一行:SourceObject="myButton" EventName="Click"

但是当我点击按钮时,我收到错误:<%= button_to 'Message me', conversations_path(sender_id: current_user.id, recipient_id: @user.id), class: 'btn btn-primary m-t' %>

我可以看到param is missing or the value is empty: conversation不在params哈希:conversation

正如在另一个主题中所建议的那样,将{"authenticity_token"=>"r5pwStXl6NwEgqqq0GT0RQxCqsGHrTVsh4Q7HviX+re5k+XOs2ioRv9kZqvDGz9Ch/6O6D1nOMjscquHQJlB+g==", "recipient_id"=>"1", "sender_id"=>"2", "controller"=>"conversations", "action"=>"create"}添加到控制器是有帮助的:

require(:conversation)

这工作了一段时间,但由于某种原因停止了工作。我该怎么解决这个问题?为什么它会停止工作?

1 个答案:

答案 0 :(得分:1)

添加&#39;对话&#39;手动到哈希似乎工作:<%= button_to 'Message me', conversations_path(conversation: { sender_id: current_user.id, recipient_id: @user.id }), class: 'btn btn-primary m-t' %>

我还必须修复控制器以考虑嵌套:

def create
  if Conversation.between(params[:conversation][:sender_id], params[:conversation][:recipient_id]).present?
    @conversation = Conversation.between(params[:conversation][:sender_id], params[:conversation][:recipient_id]).first
  else
    @conversation = Conversation.create!(conversation_params)
  end

  redirect_to conversation_messages_path(@conversation)
end