Ruby on rails 从rails表中提取信息并放入其他表中

Ruby on rails 从rails表中提取信息并放入其他表中,ruby-on-rails,Ruby On Rails,所以我有这个 <%= simple_form_for @newevent do |f| %> <div class="form-group"> <%= f.label :eventname %> <div class="row"> <div class="col-md-6"> <%= f.text_field :eventname, :autofocus => true, class: "form

所以我有这个

<%= simple_form_for @newevent do |f| %>
<div class="form-group">
  <%= f.label :eventname %>
  <div class="row">
    <div class="col-md-6">
      <%= f.text_field :eventname, :autofocus => true, class: "form-control", value: "@newevent.product_name" %>
    </div>
  </div>
</div>
谢谢


Sam

你能为你的两张桌子张贴代码吗?我对你的问题有点不清楚。两个db表很大?您想要如何编写代码?我以为您指的是HTML表,但您指的是两个数据库表(即两个不同的rails模型)。因此,据我所知,您并不是真的想要创建一个表单来编辑第一个模型的实例。您要做的是创建第二个模型的新实例,其中表单默认为第一个表中的值。听起来对吗?
  def update
    @newevent = Event.find(params[:id])
    if @newevent.update_attributes(event_params.merge createdby: current_user.id)
      flash[:success] = "Profile updated"
      redirect_to "/events"
    else
      flash.now[:alert] = 'Error updating event'
    end
  end