select_date is showing number in dropdown not month name - ruby-on-rails

Hi I am using select_date function to have dropdown in my view for month name only. But it is giving me number instead of month name in the dropdown. Can anybody help on this?
my code:
<%= select_date(Date.today, :order => [:month, :year], :discard_day => true, :use_short_month => true) %>
Thanks in advance
Sumanta

I do not see any issue with syntax, I tried the same and got the expected result - Month in dropdown. As suggested please restart your server.

Related

Rails: Select helpers are sending get request

i'm currently getting an issue with this simple code :
=form_tag payments_path, :method => :post, :id => "braintree-payment-form" do
= select_month(14, :use_month_numbers => true)
= select_year(Time.now.year, :start_year => Time.now.year, :end_year => Time.now.year + 10)
In fact, when i select a value in one of the two selects above, it automatically to a get request on the current URL with the parameter i selected
exemple: if i click on 2013 in select_year it lead to /payments/2013
Anyone have a clue about it? It's exetremely annoying, i ran through this issue previouly and couldn't have found a proper solution.
Thanks!
UPDATE:
When i put these two selects out of the form tag, il also redirect me to /payment/selected_value, i really don't understand why it does that?
I tried put a e.preventDefault() in JS on the change of the selects but it has no effect

Disable Previous Months in date_select Ruby on Rails

I want to create a month drop down list so that the previous months of the current year do not appear.
Right now my code is :
<%= f.date_select :card_expires_on, :discard_day => true, :start_year => Date.today.year, :end_year => (Date.today.year+10), :add_month_numbers => true %>
it shows me all the months now, but I want to remove or hide the past months..Is there a way?
Thanks in advance! :-)
I haven't tested this but I think it should work.
<%= select nil, "name_of_your_model[card_expires_on(1i)]", (Date.today.year..Date.today.year+10).collect { |y| y }, options = {}, id: "card_expires_on_1i" %>
<%= select nil, "name_of_your_model[card_expires_on(2i)]", (Date.today..Date.today.end_of_year).collect { |d| ["#{d.strftime('%m')} - #{d.strftime('%B')}", d.strftime('%m')] }.uniq, options = {}, id: "card_expires_on_2i" %>
<%= text_field_tag "name_of_your_model[card_expires_on(3i)]", nil, type: 'hidden', value: Date.today.day, id: "card_expires_on_3i" %>
Basically when you put date_select in your form it creates three selects. Rails then uses the "(1i)", "(2i)", and "(3i)" to bring the year, month, and day, respectively, back together. Make sure you change "name_of_your_model" to the name of the model used for the form and the value of the text_field to what ever default day you want.
Update
I just tested this and it did work!
Seems to me like you should be able to add this to a helper. I'd shy away from javascript
adding your own method for remaining_months() or some such thing would be much simpler to use.

Rails 3 Formtastic. How can I make formtastic display only the month and year fields WITHOUT the day?

I need formtastic to display only month and year fields, WITHOUT the day fields.
The datepicker is nice but it shows the whole calendar. I don't want the datepicker.
f.input :accounting_month, :label => "Accounting month", :as => :datepicker
All I need is the month and year.
There is a way to do this:
<%= f.input :accounting_month, :label => "Accounting month", :order => [:month, :year]
This will automatically hide the "day" input and give it a default value of 1.
try this
f.input :accounting_month, :as => :date_select, :discard_day => true
It doesn't work that way because without day this implies 28-31 (depending on month) days and it could be any one of them. If you use want to store a month-year selection without day you'll see it is a range of dates, not "a" date.
Advice with dates is to always store the whole date as a date field. If you only know month and year you'll need to have two (non-date) fields, one for each. But as you can see it's going to lose you a lot and you'll need to custom craft each field, validate it, etc. major pain so needs pretty good reason to do it..
The only other thing I can suggest is:
create a hidden div, or apply css if you can't 'get inside' the standard date field on the form, for the 'day'. Then set the value to always be 01. Then you might have a 'date' set of fields that will save 01-month-year to the database. This is definitely a 'hack'!
With the new syntax in Ruby 1.9
f.input :date, as: :date_select, discard_day: true

Rails Time Select, rearrange components

The default rails datetime form builder provides the following form elements as select boxes...
[YYYY] [MONTH] [DD] - [HH]:[MM]
... in 24 hour time.
I would like to present my users with:
[MON.] [DD] [YYYY] - [HH]:[MM] [AM/PM]
How do you do that?
datetime_select helper has lots of different options. I never bothered to remember them all so I use this apidock page as a reference (datetime_select and date_select have similar options).
In you case, you'll need to set :order array, :ampm to true, etc.
Edit: ok, I actually bothered to write the option hash you'll need:
date_select("question", "answered_at", :ampm => true, :order => [:month, :day, :year], :use_short_month => true)

Scaffolding A model with an attribute of type datetime creates a 10 years range in the form

For a simple rails application ( 1.86 /2.3.5) , lets say I run a simple scaffold
script/generate scaffold blog title:string content:text published:date
When I open up the new / edit view for the blog controller in index/new.html.erb , I see that the drop down enabler for date select has a date range of 2005 - 2015 , i.e 5 years +/-
I tried to change this default behavior by introducing this code
f.date_select :entered,
:start_year => 1970,
:end_year => 2020
Apparently this has no impact to the behavior mentioned above. How do I increase the date_select range which seems to be default?
This seems to be ok. Except did you put it inside the <%= %> ?
Edit: Also i noticed that you say your scaffold has published column whereas your date_select refers to the entered column.
As in, <%= f.date_select :published, :start_year => 1970, :end_year => 2020 %>
If that doesn't work you can also try,
<%= f.date_select :published, :start_year => Time.now.year - 40, :end_year => Time.now.year + 10 %>
I tried it and it works for me. Cheers! :)

Resources