Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 用于私人消息传递的Rails表单_Ruby On Rails_Nested Attributes - Fatal编程技术网

Ruby on rails 用于私人消息传递的Rails表单

Ruby on rails 用于私人消息传递的Rails表单,ruby-on-rails,nested-attributes,Ruby On Rails,Nested Attributes,我正在尝试在我的应用程序上创建两个用户之间的私人消息功能,我在这里遇到了麻烦 首先,这里是Schema.rb create_table "conversations", :force => true do |t| t.string "conversation_subject end create_table "messages", :force => true do |t| t.string "content" t.integer "user_id

我正在尝试在我的应用程序上创建两个用户之间的私人消息功能,我在这里遇到了麻烦

首先,这里是Schema.rb

create_table "conversations", :force => true do |t|
    t.string   "conversation_subject
end

create_table "messages", :force => true do |t|
    t.string   "content"
    t.integer  "user_id"
    t.integer  "conversation_id"
end

create_table "participants", :force => true do |t|
    t.integer  "conversation_id"
    t.integer  "user_id"
end

conversations has_many :messages, :participants
        users has_many :messages, :participants
开始对话的表单:

<%= form_for @conversation do |f| %>

    <div class="field">
    <strong>Subject</strong><br />
    <%= f.text_field :conversation_subject %>

    </div>
    <div class="actions">
<%= f.submit "Submit" %>
    </div>
 <% end %>
在上面的表格中,我想要

<%=f.text_area :content %> 
对于消息,只需单击一下它就可以创建对话和消息,但由于用户id的原因,我不能在这里使用嵌套属性 你可以?但据我所知,你不能

有没有一种方法可以在一个表单上处理来自两个不同模型的属性而不使用嵌套属性? 注意:我知道用户id可以从消息中删除,并且理论上仍然有一个功能性的消息传递系统,但我认为为了将每条消息与发送者关联起来,有必要将其包括在内

我可能想到的唯一解决办法是在对话中添加内容,并在第一次创建对话时将其传递到消息中。这就是我所能想到的db设计。这有内在缺陷吗? 任何帮助都会很好。我是一个rails初学者


谢谢

我很难跟上漫长的一天,但这有帮助吗

信息


嗨,凯尔,谢谢。我将对此进行研究,但你认为你能帮助我理解如何创建它吗?我以前从未见过这种情况
belongs_to :recipient, :classname => 'User'
belongs_to :sender, :classname => 'User'

create_table "messages", :force => true do |t|
    t.string   "content"
    t.integer  "recipient_id"
    t.integer  "sender_id"
    t.integer  "conversation_id"
end