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

  • Home
  • SEARCH
  • 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 7660345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:27:11+00:00 2026-05-31T13:27:11+00:00

I’m new to Rails so sorry for the extremely basic question. I’m trying to

  • 0

I’m new to Rails so sorry for the extremely basic question. I’m trying to store the value of a jQuery UI Slider in my database when a form is submitted. For other elements such as a text_area this can be done by
<%= f.text_area :my_score %> or for a date with datepicker (using the jQuery Datepicker Rails plugin): <%= f.datepicker :my_date %>. However, I am having trouble finding a plugin for the slider and from my research it seems the best way is through the use of hidden_field. However, I don’t know the correct notation for taking the value of the slider and correctly passing it to the form. Any help would be greatly appreciated.

<div id="slider"></div>
<input type="hidden" id="hidden"/>
<%= f.hidden_field :my_score, :value => (what goes here?) %>

Javascript for the slider:

<script>
$(function() {
    $( "#slider" ).slider({
        value:100,
        min: 5,
        max: 200,
        step: 5,
        slide: function( event, ui ) {
            $( "#amount" ).val( ui.value );
        },

        change: function(event, ui) {
           $('#hidden').attr('value', ui.value);
           }
    });
    $( "#amount" ).val( $( "#slider" ).slider( "value" ) );
});
</script>
  • 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-31T13:27:12+00:00Added an answer on May 31, 2026 at 1:27 pm

    Your view code should just be:

    <div id="slider"></div>
    <%= f.hidden_field :my_score %>
    

    You already have a hidden field, don’t need the second one. Also no need for a value, rails will put one in if there is one already there (ie. on edit).

    As for your javascript, you would have the change event like this:

    change: function(event, ui) {
       $('input#model_name_my_score').val(ui.value);
    }
    

    I don’t know the exact ID your hidden field will have, but it’s usually model_name_field_name. You will need to check that.

    The last thing you will need to do is set your slider to the right value on page load (assuming there is an edit version of your form and an existing value might be there).

    $( "#slider" ).slider({
            value: $('input#model_name_my_score').val(),
    

    If you want 100 to be the default when creating a new object, then you should set that 100 in the model or where ever you like to set defaults, that way rails will pre-populate the hidden field with that value on a “new” form. You might check out a gem like https://github.com/FooBarWidget/default_value_for if you don’t have a way to handle default values yet.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.