【发布时间】:2015-06-27 05:10:03
【问题描述】:
这是我的new.html.erb
<%= form_for :simulation, url: simulations_path do |f| %>
<div class="form-group">
<%= f.label :Name %>
<div class="row">
<div class="col-sm-2">
<%= f.text_field :name, class: 'form-control' %>
</div>
</div>
</div>
<div class="form-group">
<%= f.label :'Rendering Option' %>
<div class="Dropdown">
<div class="col-sm-4">
<%= select_tag(:is_random, options_for_select([['Random', true], ['No Opinion', false]], selected: :is_random )) %>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<%= f.submit 'Submit', class: 'btn btn-primary' %>
</div>
simulations_controller.rb
class SimulationsController < ApplicationController
def index
@simulations = Simulation.all
end
def new
end
def create
@simulation = Simulation.new(simulation_params)
@simulation.save
redirect_to @simulation
end
def show
@simulation = Simulation.find(params[:id])
end
结束
Simulation.rb(模型类)
class Simulation < ActiveRecord::Base
belongs_to :user
end
Schema.rb
create_table "simulations", force: :cascade do |t|
t.string "name"
t.boolean "is_random"
end
我无法在数据库中设置:is_random 值,而休息很好。我在这里做错了什么?我检查了sqlite数据库中的值,is_random列中有null条目。
【问题讨论】:
-
@ArupRakshit 我是 ruby 的新手,正在寻找一种开始开发的方法。
select_tag有什么问题吗?
标签: ruby ruby-on-rails-4 view controller