Unable to click radio button in Ruby ActiveAdmin - ruby-on-rails

I am displaying a form using ruby on rails as follows.
form do |f|
f.semantic_errors *f.object.errors.keys
# Form creation
f.inputs "User" do
f.input :first_name
f.input :last_name
f.input :email
f.input :phone_number, required: false, as: :number
f.input :password
f.input :text_sms, as: :radio, :label => "Receive sms", :checked => "Yes"
end
f.action
end
This displays the form correctly, but the problem exists when I click the radio button. I am unable to select the radio button.
By default Yes is selected, but when I click on No, it doesn't allow me.
Any help will be appreciated.
Rails version : 4.2.0

There is way, Try to replace your with
f.input :text_sms, as: :radio, :label => "Receive sms",:collection => [ ['Yes','yes',{:checked => true}], ['No','no'] ]
As given below:
form do |f|
f.semantic_errors *f.object.errors.keys
# Form creation
f.inputs "User" do
f.input :first_name
f.input :last_name
f.input :email
f.input :phone_number, required: false, as: :number
f.input :password
f.input :text_sms, as: :radio, :label => "Receive sms",:collection => [ ['Yes','yes',{:checked => true}], ['No','no'] ]
end
f.action
end

Related

How can i save check boxes value to database in active admin?

I am new to ruby on rails and active admin, I need to create check boxes for registration fees. while I checked, the value from checkbox is not saved to the database. can anyone help me ??
form do |f|
f.inputs do
f.input :name, label: "Student Name"
f.input :dob,:label => "Date of Birth"
f.input :age,:label => "Age"
f.input :gender, as: :radio, :label => "Gender", :collection => [ "Male", "Female"]
f.input :reg_fee, :as => :check_boxes, :collection => RegChargeSetup.all.map{|v| ["#{v.reg_fee}"]}
end
f.actions
end
From your code, you are taking array of arrays, instead you should take array of strings,
So, change
f.input :reg_fee, :as => :check_boxes, :collection => RegChargeSetup.all.map{|v| ["#{v.reg_fee}"]}
to,
f.input :reg_fee, :as => :check_boxes, :collection => RegChargeSetup.all.map{|v| "#{v.reg_fee}"}
form do |f|
f.inputs do
f.input :name, label: "Student Name"
f.input :dob,:label => "Date of Birth"
f.input :age,:label => "Age"
f.input :gender, as: :radio, :label => "Gender", :collection => [ "Male", "Female"]
f.input :reg_fee, :as => :check_boxes, :collection => RegChargeSetup.all.map{|v| "#{v.reg_fee}"}
end
f.actions
end

active admin adding paren't id automatically

I'm using rails' active admin and working on a create screen for a model that belongs_to a parent. I'm getting an unpermitted_param error because activeadmin is automatically adding the parent's id to the form's parameters to be submitted. However, the parameter is being added outside of the model's hash. Here are the params submitted:
{"utf8"=>"✓",
"authenticity_token"=>"9MBGkptu3jjLd4Zoy6lLUe1r6hW9TwRAmmiUNz2SwvQapRYv8nvOqZKWZKhgn9TEIXwNiD+IheQERVs+DpUgfA==",
"wedding_cake"=>{"client_id"=>"1", "first_name"=>"bob",
"last_name"=>"smith", "address"=>"11 big circle",
"city"=>"boston", "state"=>"ma ", "zip"=>"01234",
"phone"=>"1234567890", "email"=>"", "guests"=>"150",
"time"=>"12:30pm", "special_instructions"=>"", "package"=>"lake view
pavillion", "flower_price"=>"0", "rolled_chocolate_price"=>"0",
"other_price"=>"0", "tiering_price"=>"0", "deposit"=>"50",
"balance"=>"150", "vendor_balance"=>"0", "delivery_price"=>"0",
"consultant"=>"peter", "date(1i)"=>"2019", "date(2i)"=>"11",
"date(3i)"=>"18", "slice_price"=>"3.50",
"appointment_date(1i)"=>"2018", "appointment_date(2i)"=>"10",
"appointment_date(3i)"=>"16"}, "commit"=>"Create wedding cake",
"client_id"=>"1"}
wedding_cake belongs to client and should have a client_id (which it does). However, as you can see there is another client_id outside of wedding_cake. Here is the code I am using to generate the form:
form do |f|
inputs 'Venue Info' do
f.input :client_id, :as => :hidden, :input_html => { :value => f.object.client_id }
f.input :first_name
f.input :last_name
f.input :address
f.input :city
f.input :state
f.input :zip
f.input :phone
f.input :email
end
inputs 'Cake Info' do
f.input :guests
f.input :time
f.input :special_instructions
f.input :package
f.input :flower_price
f.input :rolled_chocolate_price
f.input :other_price
f.input :tiering_price
f.input :deposit
f.input :balance
f.input :vendor_balance
f.input :delivery_price
f.input :consultant
f.input :date
f.input :slice_price
f.input :appointment_date
end
f.submit
end
my strong_parameters are set up as such:
I have my permitted_params set as such in my activeadmin registration: permit_params :client_id, :base_price, :first_name, :last_name, :address, :city, :state, :zip, :phone, :email, :guests, :time, :special_instructions, :package, :flower_price, :rolled_chocolate_price, :other_price, :tiering_price, :deposit, :balance, :vendor_balance, :delivery_price, :consultant, :date, :slice_price, :appointment_date

Conditional Show/Hide in Active Admin

I have this form in Active Admin:
form(:html => { :multipart => true }) do |f|
f.inputs 'Home Carousel Image' do
f.input :name
f.input :file, as: :file
f.input :headline_text, as: :html_editor
f.input :button_text
f.input :featured_image?
f.input :headline_text
f.input :button_text
end
actions
end
featured_image? is a boolean. I was hoping to see if a user selects this (switching it to true), only then would the input fields for :headline_text and :button_text be displayed. Otherwise, these two fields will be hidden on the form.
Is this possible?
Thanks
Yes, just use if:
f.input :featured_image?
if f.object.featured_image?
f.input :headline_text
f.input :button_text
end
Use f.object to take instance of your model.

Passing URL Parameter to Drop Down

I have a simple form:
<%= f.input :type, :required => true, :collection => ["Nonprofit","School","Company"], :hint => "Note: nonprofits will need to provide proof of nonprofit status", :input_html => { :value => params['type'] } %>
<%= f.input :name, :label => "Organization" %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :email %>
A user gets to this page through a url like http://www.website.com/org/signup?type=Company
I can use this format to enter a value into a field like name or email, but can't figure out how to pass the param to the drop down.
I've already tried a few things including changing :value to :selected or :option but nothing seems to work.
Alright, figured it out! Posting here for future use.
<%= f.input :type, :required => true, :collection => ["Nonprofit","School","Company"], :hint => "Note: nonprofits will need to provide proof of nonprofit status", :selected => params['type'] %>
The trick is to drop the :input_html part and just use
:selected = > params['type']
Hope that helps someone in the future!

Grouping labels with simple_form

Is it possible to group inputs with simple_form?
I want "Postcode and city" to appear with one label and two inputs in one div as a group and not separately. But I cannot find a switch that turns off the label…
You can turn off the label on one input with the :label => false option.
Like this:
<%= f.input :name, :label => false %>
#rafaelfranca is right.
I am using Simple Form with an address like this:
<%= f.input :address, :placeholder => "Street + housenumber" %>
<%= f.input :zip, :label => false, :placeholder => "ZIP-code" %>
<%= f.input :locality, :label => false, :placeholder => "City/Town/Locality" %>
<%= f.input :state, :label => false, :placeholder => "State/Area" %>
<%= f.input :country, :label => false, :placeholder => "Country" %>
Then you will get only one label "Address" for the first text field. And all the next fields will show a placeholder.

Resources