I'm using devise 1.5.3 with rails 3.1.3, ruby 192, Im following this tutorial: http://ecuadoronrails.org/creando-un-sistema-de-autenticacion-de-usuarios-en-ruby-on-rails/#more-186
in my views I have:
<div><%= f.label :fecha_de_vencimiento %></br>
<%= f.date_select(:fecha_vencimiento, :start_year => 1901, :end_year => 2011, :include_blank => true) %>
but when I go to http://localhost:3000/users/sign_up
i get a textfield with the label like any other field...not a date_select field
what im doing wrong? do I need to install any gem??????
in my config/locales/en.yml
month_names: [~, Enero, Febrero, Marzo, Abril, Mayo, Junio, Julio, Agosto, Septiembre, Octubre, Noviembre, Diciembre]
I'm not hundred percent sure, but did you try that ?
<%= f.date_select :fecha_vencimiento, {:start_year => 1901, :end_year => 2011, :include_blank => true} %>
Related
I have haml that uses formtastic to specify date_select input (year,month,day):
= f.input :birthday,
start_year: 1900,
end_year: time.now.year-18,
input_html: { class: 'select2' }
Which renders me 3 select boxes with parent element class as a placeholder:
<select ... placeholder=".span1">
How to specify placeholders? Year;Month;Day would be good enough.
According to Formtastic Documentation:
<%= f.input :publish_at, :as => :date_select, :labels => { :year => "Year", :month => "Month", :day => "Day" } %>
[Edit]
If formtastic-bootstrap gem is used, you probably need to use :placeholder as it is used on the code.
Though, on master the :placeholder option is not implemented, with a TODO comment instead.
I want to input only year field in my rails form. I tried select_year but it doesn't work for me. select_date also gave me problem because my form models is in association. Is there any alternative idea.
Ref:- select_year
# Generates a select field for years that defaults to the current year that
# is named 'birth' rather than 'year'
<%= f.select_year(Date.today, :field_name => 'birth') %>
but if you don't have any column then just use
<%= select_year(Date.today) %>
Ref this and try something like
<%= select_year Date.today, :start_year => Time.now.year, :end_year => Time.now.year - 95, :field_name => :grad_year, :prefix => :profile %>
In my view I have:
<%= f.date_select :start %>
and I get the error message: can't convert Symbol into String
I know that it's related to it.date.order rule, but I see that rails-i18n include it:
https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/it.yml#L51
what's wrong here?
full back trace: https://gist.github.com/4007557
EDIT: running I18n.t 'date.order' in the console give me => [:day, :month, :year]. That it's correct... so why date_select doesn't works?
issue on GitHub repo: https://github.com/svenfuchs/rails-i18n/issues/273
I had a similar if not the same issue in the past. At the time I fixed it by using the following:
date:
order: [ !ruby/symbol day, !ruby/symbol month, !ruby/symbol year ]
As far as I understand the rails docs about date_select it wants to have a string.
If :start is the name of your I18n, you should do <%= f.date_select t(:start) %> as far as I remember.
You don't have to touch you form: it's a translation problem. You should add in your it.yml file the lines you will find here: https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale.
If like in my case you are only working with years and don't want to add translations for every language with i18n just for a year selection, you can add :locale => 'en' just for that date like this:
<%= f.date_select :start, :start_year => 1940, :end_year => Date.today.year, :discard_day => true, :discard_month => true, :locale => 'en' %>
This is a translation problem: you have to add :order rule to your it.yml file or use this line in form.
<%= f.date_select(:start, :order => [:day, :month, :year]) %>
I am trying to create a db that has a year attribute but I am having some difficulty. I created the scaffold and tryied to modify the _form.html.erb with this code:
<%= f.date_select :year, :start_year=>2000, :end_year=>Time.now.year %>
Tried to run the rails server and gave me this error:
1 error(s) on assignment of multiparameter attributes
I realized that I only wanted the year and not the day or month. Is there a way to do that? I tried :discard_month=>true but that just hides it, but still storing it.
Thanks in advance
Do something like:
<%= f.date_select :year, :order => [:year], :start_year => 2000, :end_year => Time.now.year, :prompt => {:year => "Select year"} %>
Because your year field is an int and not a datetime:
<%= f.select :year, (2000..Time.now.year).to_a, :include_blank => {:year => "Select year"} %>
Another alternative is select_year
e.g.,
select_year(Date.current, start_year: 2015, end_year: Date.current.year)
I have a form in my Rails 3 app where I want to create a select tag for just the year on a method :grad_year. I have everything working - and storing - properly using date_select and adding :discard_month and :discard_day. However when I render #profile.grad_year I get the month and day values. So I'm wondering how to store and render only the year for #profile.grad_year?
Here is the form:
<%= f.date_select :grad_year, {:start_year => Time.now.year, :end_year => Time.now.year - 95, :discard_day => true, :discard_month => true}, :selected => #profile.grad_year %>
In my migration:
t.date :grad_year
Rails has a select_year helper:
http://apidock.com/rails/ActionView/Helpers/DateHelper/select_year
So your code should look like:
f.select_year(Date.today, :start_year => Time.now.year, :end_year => Time.now.year - 95, :field_name => 'grad_year')
Assembling all of the above from #alex_peattie's answer, I arrived at the following:
<%= select_year Date.today, :start_year => Time.now.year, :end_year => Time.now.year - 95, :field_name => :grad_year, :prefix => :profile %>
As with the OP's question, my case was done within a form_for block, so f.select_year threw an exception. But if you just use the documented :field_name option, the tag will have the id date_grad_year and name date[grad_year] which are not what Rails expects. Using the (documented only at the very top of the API) :prefix option changes date to profile.
So this is better than the ##%$^*& html_options hash, which, despite using rails for 5 years now, I cannot seem to get right without five tries :-).
Oh Rails, how I love you, yet at the same time am sure glad Stack Overflow is around to help us all understand your delightful idiosyncrasies!
This select_year function is totally screwy.
Here is finally what works:
<%= form_for(#user) do |f| %>
<%= select_year current_user.birth_year, { :prompt => "Year",
:start_year => Time.zone.now.year - 13,
:end_year => Time.zone.now.year - 80,
:field_name => :birth_year,
:prefix => :user },
class:"form-control" %>
<% ... %>
it aught to be like this in rails:
<%= f.select_year :birth_year, { :prompt => "Year",
:start_year => Time.zone.now.year - 13,
:end_year => Time.zone.now.year - 80},
class:"form-control" %>