Ruby on rails 表格过帐空白值

Ruby on rails 表格过帐空白值,ruby-on-rails,Ruby On Rails,我正在论坛系统之上构建一个私人消息系统(使用SO代码)。将新消息添加到私人消息会话时,正文为空,但时间戳和用户是正确的 该系统的工作原理如下。与第一篇帖子和收件人建立对话。这是从SO问题8205284中逐字复制的 现在,我正试图通过user_conversation controller(构建对话的控制器)中的编辑/更新操作向对话添加新消息 路线: resources :users do resources :conversations, :controller => "user_

我正在论坛系统之上构建一个私人消息系统(使用SO代码)。将新消息添加到私人消息会话时,正文为空,但时间戳和用户是正确的

该系统的工作原理如下。与第一篇帖子和收件人建立对话。这是从SO问题8205284中逐字复制的

现在,我正试图通过user_conversation controller(构建对话的控制器)中的编辑/更新操作向对话添加新消息

路线:

resources :users do
    resources :conversations, :controller => "user_conversations"
end

resources :conversations, :controller => "user_conversations" do
    resources :messages
end
控制器:

def edit
 @conversation = UserConversation.find(params[:id]) 
 @message = Message.new
end

def update
@conversation = UserConversation.find(params[:id]) 
@message = @conversation.messages.build(params[:message])
@message.user = current_user
@message.conversation_id = @conversation.conversation_id
@message.body = "without this test line the message body is blank!"

if @message.save!
  redirect_to user_conversation_path(current_user, @conversation)
else
  redirect_to @conversation
end
end
查看以显示对话和嵌入的新消息表单:

<%= form_for(@conversation) do |c| %>
<div class="field">
<%= c.fields_for :messages do |m| %> 
<%= m.text_area :body, placeholder: "New message..." %>
<%= m.submit "New Convo Message", class: "btn btn-large btn-primary" %>
<% end %>
</div>
<%= c.submit "New Convo Message", class: "btn btn-large btn-primary" %>
<% end %>
我认为你需要:

@message = @conversation.messages.build(params[:user_conversation][:messages])
因为消息嵌套在基于参数的用户_转换中

消息对应于:

<%= c.fields_for :messages do |m| %> –

我认为您需要params[:messages],它将与您在没有运气的情况下所做的更改相对应。您可以在发出请求时发布日志中显示的params散列吗?它成功了!谢谢!:)您是如何知道:messages应该是复数的?从您的模型和您使用c.fields_表示:messages的事实来看。不管怎样,很高兴它成功了:-)
<%= c.fields_for :messages do |m| %> –