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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:19:18+00:00 2026-06-16T13:19:18+00:00

I have a Registration model and form which uses a datepicker. I want the

  • 0

I have a Registration model and form which uses a datepicker. I want the user to be only able to select dates which correspond to events (another model).

My problem is I can’t find the right way to pass the event array to javascript.

this is in the controller:

@available_dates = Event.pluck(:start_time).as_json

this is in the view:

    <script>
       var availableDates = [<%= @available_dates.to_s.html_safe %>] ;
    </script>

and this is the js:

function available(date) {
    ymd = date.getFullYear() + "-" + ('0' + (date.getMonth()+1)).slice(-2) + "-" + ('0' + date.getDate()).slice(-2);
    console.log(ymd+' : '+($.inArray(ymd, availableDates)));
    if ($.inArray(ymd, availableDates) != -1) {
        return [true, "","Available"];
    } else {
        return [false,"","unAvailable"];
    }
}
$("#registration_date").datepicker({ beforeShowDay: available, dateFormat: "yy-mm-dd"});

I think I’m doing something wrong in the view since the js array seems to be empty looking at the console…

any help would be greatly appreciated

  • 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-16T13:19:19+00:00Added an answer on June 16, 2026 at 1:19 pm

    In the question comments you have mentioned @available_dates.to_s returns "[\"2013-01-05\", \"2013-02-02\", \"2013-03-02\"]". This itself will render the array on the page so no need to “box it up” again.

    Try changing the following line:

    var availableDates = [<%= @available_dates.to_s.html_safe %>] ;
    

    to this:

    var availableDates = <%= @available_dates.to_s.html_safe %>;
    

    Hope it helps.

    If it doesn’t you are either clearing the value of @available_dates somewhere further in your code or @available_dates is not available in the context of your view. Have your tried stepping through the code using debugger;?

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

Sidebar

Related Questions

In my web application i have registration form, when user register i want to
I have a simple bean defining user credentials on signup registration form model: public
I have a user registration form, in which I am trying to display a
I have a user registration form in my Django application which collects additional data
I have a user facing form, which is generated from a model. The model
I am trying to build a registration form. I have a model for all
on my web site I want to have login/registration form in modal window done
I have currently a website which lets every user register, but I want to
I have a registration form where user has to enter his credentials plus a
I have an MVC3 Internet Application. Basically it has a registration form, which has

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.