Skip to content
This repository has been archived by the owner on Jun 21, 2018. It is now read-only.

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

Open
jzellman opened this issue Oct 14, 2013 · 6 comments

Comments

@jzellman
Copy link

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
Copy link
Collaborator

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
Copy link
Collaborator

Closing, but I'll reopen if need be.

@jzellman
Copy link
Author

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
Copy link

nicdal commented Oct 16, 2013

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.

@marcandre marcandre reopened this Oct 16, 2013
@bigtunacan
Copy link

Bump

@paxer
Copy link

paxer commented Oct 14, 2014

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants