title: saving boolean values to postgres database using ruby on rails
body: <p>I've been working on a old rails project for a bit now. Since I haven't worked with rails in some time I'm a bit rusty and need some help along the way.</p>
  
  <p>The thing is that I'm adding a pick up options to a E commerce web.</p>
  
  <p>The backend is driven by <code>active admin</code></p>
  
  <p>When the customer is checking out its product.
  He gets the option to pick it up in the store or have it sent.</p>
  
  <p>And I want the order to show in the backend whether the product should be sent or if it is picked up at the store. </p>
  
  <p>I'm kind of stuck here, and the delivery options don't seems to be saving to the database.... It would be so nice if someone could help me with this. </p>
  
  <p>here is the html for the pick up option. it is located in the <code>views/orders/_form.html.erb</code></p>
  
  <pre><code>&lt;div class="col-md-5 pick-up-buttons" id="country_div"&gt;
    &lt;li&gt;
      &lt;%= f.radio_button :pick_up, "1", checked: false, data: { question: "Pick up your items in the store" } %&gt; 
      &lt;%= f.label :pick_up, "Pick up your items in the store" %&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;%= f.radio_button :pick_up, "0", checked: true,  data: { question: "Send the items by mail" } %&gt; 
      &lt;%= f.label :pick_up, "Send the items by mail" %&gt;
    &lt;/li&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p>and here is a part of the <code>schema.rb</code> file  </p>
  
  <pre><code>create_table "orders", force: :cascade do |t|
    t.string   "name"
    t.string   "email"
    t.text     "address"
    t.string   "city"
    t.string   "country"
    t.datetime "created_at",                 null: false
    t.datetime "updated_at",                 null: false
    t.boolean  "shipped",    default: false
    t.boolean  "pick_up",    default: false
    t.string   "delivery"
  end
  </code></pre>
  
  <p>And here is the <code>orders_controller.rb</code></p>
  
  <pre><code>class OrdersController &lt; ApplicationController
    include CurrentCart
    before_action :set_cart, only: [:new, :create]
    before_action :set_order, only: [:show, :edit, :destroy]
  
    def index
      @orders = Order.all? 
    end
  
    def new
      @images  = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"]
      @random_no = rand(5)
      @random_image = @images[@random_no]
  
      if @cart.product_items.empty?
        redirect_to root_url, notice: 'Your Cart is Empty'
        return
      end
  
      @order = Order.new
      @client_token = Braintree::ClientToken.generate
  
      @del_cost_euro = 20
    end
  
    def create
      @order = Order.new(order_params)
      if @order.save
        charge
        if @result.success?
          @order.add_product_items_from_cart(@cart)
          Cart.destroy(session[:cart_id])
          session[:cart_id] = nil
          OrderNotifier.received(@order).deliver 
          redirect_to root_url, notice: 'Thank You for Your Order'
        else
          flash[:error] = 'Please Check Your Cart'
          redirect_to root_url, alert: @result.message
          @order.destroy
        end
      else
        @client_token = Braintree::ClientToken.generate
        render :new
      end
    end
  
    def show
    end
  
    def destroy
      @order.destroy
      redirect_to root_url, notice: 'Order deleted'
    end
  
    private
    def set_order
      @order = Order.find(params[:id])
    end
  
    def order_params
      params.require(:order).permit(:name, :email, :address, :city, :country, :pick_up, :delivery)
    end
  
    def charge
      @result = Braintree::Transaction.sale(
        amount: @cart.total_price_usd,
        payment_method_nonce: params[:payment_method_nonce] )
    end
  end
  </code></pre>
  
  <p>And here is the <code>app/admin/order.rb</code></p>
  
  <pre><code>ActiveAdmin.register Order do
  
  permit_params :shipped
  
  after_update do |order|
    OrderNotifier.shipped(@order).deliver if order.shipped
  end
  
  show do |order|
    panel 'Customer Details' do
      attributes_table_for order, :name, :email, :address, :city, :country
    end
  
    panel 'Created' do
      "#{time_ago_in_words order.created_at} ago"
    end
  
    panel 'Shipped' do
      order.shipped
    end
  
    panel 'delivery' do
      order.pick_up
    end
  
    panel 'Order Details' do
      table_for(order.product_items) do 
        column 'Product' do |item|
          item.product.title
        end
  
        column 'Quantity' do |item|
          item.quantity
        end
  
        column 'Price Euro' do |item|
          number_to_currency item.total_price_eur
        end
  
        column 'Price USD' do |item|
          number_to_currency item.total_price_usd
        end
      end
    end
  
    panel 'Order Total USD' do 
      number_to_currency order.total_price_usd
    end
  
    panel 'Order Total Euro' do 
      number_to_currency order.total_price_eur
    end
  end
  </code></pre>