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 8289975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:39:33+00:00 2026-06-08T12:39:33+00:00

I am using a button-group as a radio button to capture user input for

  • 0

I am using a button-group as a radio button to capture user input for a boolean field in my database. I have a wedding model with a boolean field :rsvp. The form below seems to capture the data. However, if I refresh the page, the button is no longer toggled with the user’s choice. My question is, how to I get the button to persist the user’s choice, even if the page is refreshed, or if the user logs out and logs in again?

Models

 class User < ActiveRecord::Base
  has_one :wedding
 end

 class Wedding < ActiveRecord::Base
  belongs_to :user
 end

Controllers

 class WeddingsController < ApplicationController

   def new
     @wedding = Wedding.new
   end

   def create
     @wedding = current_user.build_wedding(params[:wedding])
      if @wedding.save
       redirect_to root_path
     else
       render 'new'
     end
   end

 class StaticPagesController < ApplicationController
   def home
    @wedding = Wedding.new
   end

View:

home.html.erb

  <%= form_for(@wedding, :remote => true) do |f| %>
     <div class="btn-group-wrap">
          <div class="btn-group" data-toggle="buttons-radio">
             <%= f.button 'Yes', :class => "btn btn-large btn", :value => "1", :name => "wedding[rsvp]" %>
              <%= f.button 'No', :class => "btn btn-large btn", :value => "0", :name => "wedding[rsvp]" %>
          </div>
     </div>
  <% end %>
  • 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-06-08T12:39:35+00:00Added an answer on June 8, 2026 at 12:39 pm

    Here is how I ended up doing it (using Javascript). Not sure if it is the best way or not. I added an ID tag to each button and then toggled that button using javascript and a conditional that depends on the value in the my database.

     <div class="btn-group" data-toggle="buttons-radio">         
            <%= f.button :rsvp, :id => "rsvp_true", :class => "btn btn-large btn", :value => "1", :name => "wedding[rsvp]" %>
            <%= f.button :rsvp, :id => "rsvp_false", :class => "btn btn-large btn", :value => "0", :name => "wedding[rsvp]" %>      
     </div>
    
     <script>
       $(document).ready(function() {
      <% if current_user.wedding.rsvp == true %>
        $('#rsvp_true').button('toggle');
      <% else %>
        $('#rsvp_false').button('toggle');
      <% end %>
       });
     </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a radio button group that gets it's values using an @Dblookup. In
I am using an asp radio button group to list out answers in a
I'm using a Dojo radio button group in a mobile Xpage and it is
I've got this HTML form where I have multiple input elements: text, radio, and
I have this group of radio buttons in which each of individual button has
I have some stray text next to radio buttons in a radio button group.
I have a radio group with two radiobuttons. each button has a custom selector.
I have a bunch of radiobuttons in a group and each radio button has
I am using group radio buttons.What i want is that when i have selected
I constructed the radio button group using f:selectItems . I constructed the radio button

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.