Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6812215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:25:20+00:00 2026-05-26T20:25:20+00:00

<% semantic_form_for(@buss, {:url => url, :html => {….}}) do |f| %> …. <%= f.input

  • 0

<% semantic_form_for(@buss, {:url => url, :html => {….}}) do |f| %>
….
<%= f.input :country, :label => ‘Country:’, :include_blank => true %>
….

and country select is rendered as..

 <li class="select required" id="business_country_input">
    <label for="business_country_id">Country:</label>
    <select id="business_country_id" name="business[country_id]">
      <option value=""></option>
      <option value="221">Åland Islands</option>
      <option value="32">Algeria</option>
      <option value="9">American Samoa</option>
     </select>
  </li>

So, how do i add extra parameters for option tag, say for example i need something like

 .....
  <option value="221" country-code="AA">Aland Islands</option>  
  <option value="32"  country-code="BB">Algeria</option>  
  <option value="9"  country-code="CC">American Samoa</option>  
 .....

Basically something like

<select id="country">
  <% @countries.each do |c| %>
     <option value="<%= c.id %>" country-code="<%= c.code %>"><%= c.name %></option>
  <% end %>
</select>

How it can be done with formtastic ?.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:25:20+00:00Added an answer on May 26, 2026 at 8:25 pm

    First define a helper for building your custom country options:

    def custom_country_options
      countries = ActionView::Helpers::FormOptionsHelper::COUNTRIES.map do |c|
        [c.downcase, c, {:country-code => c[0..1]}]
        #=> ["algeria", "Algeria", "Al"] 
      end
    
      return options_for_select(countries)
    end
    

    then in your form, you should be able to do:

    <%= f.input :country, :as => :select, :collection => custom_country_options %>
    

    Note: there’s a chance that f.input :country will always create the default country dropdown, you may have to do f.input :custom_country or similar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<% semantic_form_for(@product, :html => {:multipart => true}) do |f| %> <% f.inputs do %>
I have the following form with Formtastic: = semantic_form_for @user, :url=> url_for(register_path), :html =>
I am using semantic_form_for like following : = semantic_form_for(@car) do |v| -v.inputs do =v.input
I have this form - semantic_form_for :qualification, :url => { :controller => 'qualifications', :action
So i have a form generated by formtastic and it's working : <%semantic_form_for(Model.new,:url=>{:action=>fooobar}) do
I have a formtastic form like the following: = semantic_form_for @record, :remote => true,
<%-roles = Role.all%> <%= panel Edit do%> <%= semantic_form_for(resource, :as => resource_name, :url =>
I have a form built with formtastic, the code is <%= semantic_form_for @plan, :html
Semantic HTML makes it easier for Google to crawl and 'understand' a website but
We have a class whose semantic behaviour is like the following :- struct Sample

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.