数据未存储在表轨中

时间:2018-05-23 18:11:10

标签: ruby-on-rails ruby

我已经生成了一个迁移,通过使用rails generate migration add_status_to_fundings在fundings表中添加状态字段。我已经添加了迁移文件,并在其中创建了 add_column:fundings,:status,:string 然后 rails db:migrate 在架构状态中添加到资金表中。但无论我输入的数据是什么,它都不会存储在资金表中。 show.html.erb文件中的数据都不显示。请帮助。

_form.html.erb

<div class = "form-group">
        <div class="control-label col-sm-2">
          <%= form.label :status %>
        </div>
        <div class="col-sm-8">
          <%= form.text_field :status %>
        </div>
      </div> 
      <div class="form-group">
        <div class="col-sm-10">
          <%= form.submit "Apply", class: 'btn btn-primary btn-lg' %>
</div>
</div>

show.html.erb

<p><strong>Status: </strong><%= @funding.status %></p><br>

migrationfile

class AddStatusToFundings < ActiveRecord::Migration[5.2]
  def change
    add_column :fundings, :status, :string
  end
end

rails console

<Funding id: 1, describe_activity: "10 players in each team", type_of_activity: "Cricket", season: "Fall", activity_details: "best outdoor games ", name_of_organisation: "BCCI", activity_start_date: "2018-12-12", number_of_weeks: "6", days_per_week: "6", hours_per_day: "6", program_registration_cost: 100, family_contribution: "10", other_funds: 20, other_fund_provider: "Arni", amount_requested: 70, created_at: "2018-05-23 17:56:03", updated_at: "2018-05-23 17:56:03", child_id: 1, status: nil>

1 个答案:

答案 0 :(得分:1)

似乎你遇到的问题不在于表格本身。你只是忘了将:status添加到你允许的参数中。

也许你的控制器里有这样的东西

private
  def funding_params
    params.require(:funding).permit(:describe_activity, :type_of_activity..., :status)
  end

只需添加:允许的状态