timcharper / calendar_date_select

A previously popular but no longer maintained JavaScript DatePicker for RubyOnRails (and others)
http://code.google.com/p/calendardateselect/
Other
409 stars 179 forks source link

Rails 3.2; Is a config/initializers/calendar_date_select file needed? Am I doing it right? #37

Open jzellman opened 11 years ago

jzellman commented 11 years ago

Hi,

I'm in the process of upgrading an app from Rails 2.3 to 3.2. In order to get the plugin working correctly I had to do the following:

Add calendar date select to the Gemfile:

gem 'calendar_date_select', '2.0.0', 
    :git => 'git://github.com/timcharper/calendar_date_select.git'

Add the following to my layout/application (for silver style):

<%= stylesheet_link_tag 'calendar_date_select/silver'  %> 
<%= javascript_include_tag 'calendar_date_select/calendar_date_select' %>

Add the css and js assets to the asset pipeline in config/application.rb:

config.assets.precompile += ['calendar_date_select/*.css', 'calendar_date_select/*.js'] 

Create the file config/initializers/calendar_date_select.rb with the following:

require 'calendar_date_select'    
ActionView::Helpers::FormHelper.send(:include, CalendarDateSelect::FormHelpers) 
ActionView::Base.send(:include, CalendarDateSelect::FormHelpers)   
ActionView::Base.send(:include, CalendarDateSelect::IncludesHelper) 

Without the config/initializer/calendar_date_select.rb file, the calendar_date_select helper method is no longer available in the views:

undefined method `calendar_date_select'

So my question is... is a config/initializer file required? Is there a better way to get the helpers loaded in the ActionView context?

Thanks,

Jeff

marcandre commented 11 years ago

No initializer is needed. I believe you're looking for calendar_date_select_tag (i.e. missing the _tag part).

I think calendar_date_select is available only from a form (e.g. form_for blabla do |f| ; f.calendar_date_select :some_field; ...)

PS: there's a calendar_date_select_includes helper you can use for the js/css if you like.

marcandre commented 11 years ago

Closing, but I'll reopen if need be.

jzellman commented 11 years ago

Thanks for the help, calendar_date_select_includes fixed the loading of the javascripts and stylesheets.

I'm still having an issue using f.calendar_date_select. I don't think it is a problem with calendar_date_select since I created a vanilla Rails 3.2.13 application and it worked fine there.

Unfortunately the app I inherited is a rather large app with a lot of gem dependencies. For now I'll just leave ActionView::Base.send(:include, CalendarDateSelect::FormHelpers) in an initializer as a stop gap until I can find the offending library.

Thanks again for the help!

Jeff

nicdal commented 11 years ago

I have the same issue in a old project upgraded to Rails 4.0.0.

I need to initialize ActionView::Base.send(:include, CalendarDateSelect::FormHelpers) for calendar_date_select_tag and calendar_date_select to work.

bigtunacan commented 10 years ago

Bump

paxer commented 10 years ago

have a look on this fork for Rails 4 https://github.com/bdcheung/calendar_date_select