Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.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_Forms_Erb - Fatal编程技术网

Ruby on rails 提交rails的数据表单

Ruby on rails 提交rails的数据表单,ruby-on-rails,forms,erb,Ruby On Rails,Forms,Erb,是否有人足够了解我如何将提交的数据存储到另一个模型数据库中。例如: <bottom><div class="row"> <div class="col-md-6 col-md-offset-3"> <%= form_for(@user) do |f| %> <%= f.label :name %> <%= f.text_field :name %> <%= f.labe

是否有人足够了解我如何将提交的数据存储到另一个模型数据库中。例如:

<bottom><div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= form_for(@user) do |f| %>
      <%= f.label :name %>
      <%= f.text_field :name %>

      <%= f.label :event %>
      <%= f.text_field :event %>

      <%= f.label :email %>
      <%= f.email_field :email %>

      <%= f.label :password %>
      <%= f.password_field :password %>

      <%= f.label :code %>
      <%= f.text_field :code %>


      <%= f.submit "Create", class: "btn btn-primary" %>
    <% end %>
  </div>
</div>
</bottom>

它为事件创建标签和为事件创建文本字段的那一行,有没有任何可能的方法可以将用户为此键入的内容存储在具有名称行的事件数据库中

class CreateEvents < ActiveRecord::Migration[5.0]
  def change
    create_table :events do |t|
      t.string :name

      t.timestamps
    end
  end
end
class CreateEvents

基本上,您可以使用
字段\u来解决您的问题,我认为以下代码可以工作,但我没有尝试过:

  <%= form_for(@user) do |f| %>
      ....
      <% fields_for @event do |e| %>
          <%= e.label :event %>
          <%= e.text_field :event %>
      <% end %>
      ...
  <% end %>

....
...

我收到一个错误,显示未知型号名称?有什么原因吗?在users新函数中,我没有定义新事件