Note that there are some explanatory texts on larger screens.

plurals
  1. POCan anyone help me edit a boolean with check_box?
    primarykey
    data
    text
    <p>Everything is working fine in my rails project, except for one thing. I'm trying to be able to edit a boolean with check_box. But when I go to edit, whether or not the check_box is checked, the boolean stays false. Here is my relevant code:</p> <pre><code>class SubnetsController &lt; ApplicationController # GET /subnets # GET /subnets.json def index @subnets = Subnet.all respond_to do |format| format.html # index.html.erb format.json { render :json =&gt; @subnets } end end def normal @subnets = Subnet.all respond_to do |format| format.html # normal.html.erb format.json { render :json =&gt; @subnets } end end # GET /subnets/1 # GET /subnets/1.json def show @subnet = Subnet.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render :json =&gt; @subnet } end end # GET /subnets/new # GET /subnets/new.json def new @subnet = Subnet.new respond_to do |format| format.html # new.html.erb format.json { render :json =&gt; @subnet } end end # GET /subnets/1/edit def edit @subnet = Subnet.find(params[:id]) end # POST /subnets # POST /subnets.json def create @subnet = Subnet.new(params[:subnet]) respond_to do |format| if @subnet.save format.html { redirect_to @subnet, :notice =&gt; 'Subnet was successfully created.' } format.json { render :json =&gt; @subnet, :status =&gt; :created, :location =&gt; @subnet } else format.html { render :action =&gt; "new" } format.json { render :json =&gt; @subnet.errors, :status =&gt; :unprocessable_entity } end end end # PUT /subnets/1 # PUT /subnets/1.json def update @subnet = Subnet.find(params[:id]) respond_to do |format| if @subnet.update_attributes(params[:subnet]) format.html { redirect_to @subnet, :notice =&gt; 'Subnet was successfully updated.' } format.json { head :no_content } else format.html { render :action =&gt; "edit" } format.json { render :json =&gt; @subnet.errors, :status =&gt; :unprocessable_entity } end end end # DELETE /subnets/1 # DELETE /subnets/1.json def destroy @subnet = Subnet.find(params[:id]) @subnet.destroy respond_to do |format| format.html { redirect_to subnets_url } format.json { head :no_content } end end end </code></pre> <p>View:</p> <pre><code>&lt;%= form_for(@subnet) do |f| %&gt; &lt;% if @subnet.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;h2&gt;&lt;%= pluralize(@subnet.errors.count, "error") %&gt; prohibited this subnet from being saved:&lt;/h2&gt; &lt;ul&gt; &lt;% @subnet.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="field"&gt; &lt;%= f.label :SubnetName %&gt;&lt;br /&gt; &lt;%= f.text_field :SubnetName %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :FW_Context_BridgeGroup %&gt;&lt;br /&gt; &lt;%= f.number_field :FW_Context_BridgeGroup %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :VlanNumber %&gt;&lt;br /&gt; &lt;%= f.number_field :VlanNumber %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :FwVlan %&gt;&lt;br /&gt; &lt;%= f.number_field :FwVlan %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :NetAddress %&gt;&lt;br /&gt; &lt;%= f.text_field :NetAddress %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :DefaultRouter %&gt;&lt;br /&gt; &lt;%= f.text_field :DefaultRouter %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :Netmask %&gt;&lt;br /&gt; &lt;%= f.text_field :Netmask %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :Broadcast %&gt;&lt;br /&gt; &lt;%= f.text_field :Broadcast %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :Notes %&gt;&lt;br /&gt; &lt;%= f.text_field :Notes %&gt; &lt;/div&gt; **&lt;div class="field"&gt; &lt;%= f.label :multicast %&gt;&lt;br /&gt; &lt;%= f.check_box :multicast %&gt; &lt;/div&gt;** &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;% end %&gt; </code></pre> <p>Migration:</p> <pre><code>class AddMulticast &lt; ActiveRecord::Migration def up add_column :subnets, :multicast, :boolean, :default =&gt; 0 end def down remove_column :subnets, :multicast end end </code></pre> <p>I know I'm probably missing some small piece of code. Any help would be appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload