diff --git a/lib/generators/impressionist_generator.rb b/lib/generators/impressionist_generator.rb index 30290af..008f1ec 100644 --- a/lib/generators/impressionist_generator.rb +++ b/lib/generators/impressionist_generator.rb @@ -7,6 +7,7 @@ module Impressionist def copy_config_file template 'impression.rb', 'config/initializers/impression.rb' end + end end end diff --git a/lib/generators/templates/impression-mongoid-2.rb b/lib/generators/templates/impression-mongoid-2.rb new file mode 100644 index 0000000..0d1a95e --- /dev/null +++ b/lib/generators/templates/impression-mongoid-2.rb @@ -0,0 +1 @@ +impression-mongoid-2.rb \ No newline at end of file diff --git a/lib/impressionist/controllers/mongoid/impressionist_controller.rb b/lib/impressionist/controllers/mongoid/impressionist_controller.rb index 73b5e92..426c5b8 100644 --- a/lib/impressionist/controllers/mongoid/impressionist_controller.rb +++ b/lib/impressionist/controllers/mongoid/impressionist_controller.rb @@ -1,9 +1,10 @@ ImpressionistController::InstanceMethods.send(:define_method, :direct_create_statement) do |query_params={}| # creates a statment hash that contains default values for creating an impression. # if :impressionable_id is a valid ObjectId then convert it into one + base = (defined? Moped) ? Moped::BSON : BSON query_params.reverse_merge!( :impressionable_type => controller_name.singularize.camelize, - :impressionable_id=> !Moped::BSON::ObjectId.legal?(params[:id]) ? params[:id] : Moped::BSON::ObjectId.from_string(params[:id]) + :impressionable_id=> !base::ObjectId.legal?(params[:id]) ? params[:id] : base::ObjectId.from_string(params[:id]) ) associative_create_statement(query_params) end \ No newline at end of file diff --git a/lib/impressionist/controllers/mongoid/mongoid2-impressionist_controller.rb b/lib/impressionist/controllers/mongoid/mongoid2-impressionist_controller.rb new file mode 100644 index 0000000..de005a7 --- /dev/null +++ b/lib/impressionist/controllers/mongoid/mongoid2-impressionist_controller.rb @@ -0,0 +1,10 @@ +ImpressionistController::InstanceMethods.send(:define_method, :direct_create_statement) do |query_params={}| + # creates a statment hash that contains default values for creating an impression. + # if :impressionable_id is a valid ObjectId then convert it into one + base = (defined? Moped) ? Moped::BSON :: BSON + query_params.reverse_merge!( + :impressionable_type => controller_name.singularize.camelize, + :impressionable_id=> !base::ObjectId.legal?(params[:id]) ? params[:id] : base::ObjectId.from_string(params[:id]) + ) + associative_create_statement(query_params) +end \ No newline at end of file