lib/map_fields.rb in map_fields-1.0.1 vs lib/map_fields.rb in map_fields-1.0.2
- old
+ new
@@ -10,11 +10,11 @@
def map_fields
default_options = {
:file_field => 'file',
:params => []
}
- options = default_options.merge(
+ options = default_options.merge(
self.class.read_inheritable_attribute(:map_fields_options)
)
RAILS_DEFAULT_LOGGER.debug("session[:map_fields]: #{session[:map_fields]}")
RAILS_DEFAULT_LOGGER.debug("params[options[:file_field]]: #{params[options[:file_field]]}")
@@ -40,11 +40,11 @@
else
expected_fields = self.class.read_inheritable_attribute(:map_fields_fields)
if expected_fields.respond_to?(:call)
expected_fields = expected_fields.call(params)
end
- @mapped_fields = MappedFields.new(session[:map_fields][:file],
+ @mapped_fields = MappedFields.new(session[:map_fields][:file],
expected_fields,
params[:fields],
params[:ignore_first_row])
end
end
@@ -77,30 +77,30 @@
raise @map_fields_error if @map_fields_error
@mapped_fields
end
def map_field_parameters(&block)
-
+
end
def map_fields_cleanup
if @mapped_fields
if session[:map_fields][:file]
- File.delete(session[:map_fields][:file])
+ File.delete(session[:map_fields][:file])
end
session[:map_fields] = nil
@mapped_fields = nil
@map_fields_error = nil
end
end
module ClassMethods
- def map_fields(action, fields, options = {})
+ def map_fields(actions, fields, options = {})
write_inheritable_attribute(:map_fields_fields, fields)
write_inheritable_attribute(:map_fields_options, options)
- before_filter :map_fields, :only => action
- after_filter :map_fields_cleanup, :only => action
+ before_filter :map_fields, :only => actions
+ after_filter :map_fields_cleanup, :only => actions
end
end
class MappedFields
attr_reader :mapping, :ignore_first_row, :file
@@ -112,11 +112,11 @@
@ignore_first_row = ignore_first_row
mapping.each do |k,v|
unless v.to_i == 0
#Numeric mapping
- @mapping[v.to_i - 1] = k.to_i - 1
+ @mapping[v.to_i - 1] = k.to_i - 1
#Text mapping
@mapping[fields[v.to_i-1]] = k.to_i - 1
#Symbol mapping
sym_key = fields[v.to_i-1].downcase.
gsub(/[-\s\/]+/, '_').
@@ -192,6 +192,8 @@
end
if defined?(Rails) and defined?(ActionController)
ActionController::Base.send(:include, MapFields)
ActionController::Base.view_paths.push File.expand_path(File.join(File.dirname(__FILE__), '..', 'views'))
+ #This is a hack but the above code is not enough when using bundler and Rails 2.3.5
+ ActionController::Base.view_paths.push "app/views"
end