Skip to content

Commit

Permalink
Gracefully support Rails version differences instead of doing version…
Browse files Browse the repository at this point in the history
… checks
  • Loading branch information
cbeer committed Mar 11, 2015
1 parent 881c06d commit 9ce2ef6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/models/bookmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class Bookmark < ActiveRecord::Base
belongs_to :document, polymorphic: true

validates_presence_of :user_id, :scope=>:document_id
attr_accessible :id, :document_id, :document_type, :title if Rails::VERSION::MAJOR < 4

if respond_to? :attr_accessible
attr_accessible :id, :document_id, :document_type, :title
end

def document
document_type.new document_type.unique_key => document_id
Expand Down
9 changes: 6 additions & 3 deletions app/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ class Search < ActiveRecord::Base

serialize :query_params

if Rails::VERSION::MAJOR < 4
if respond_to?(:attr_accessible)
attr_accessible :query_params

scope :none, where(:id => nil).where("id IS NOT ?", nil)
end

unless respond_to?(:none)
# polyfill
scope :none, where(id: nil).where("id IS NOT ?", nil)
end

# A Search instance is considered a saved search if it has a user_id.
Expand Down
4 changes: 3 additions & 1 deletion lib/generators/blacklight/user_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def inject_blacklight_user_behavior
file_path = "app/models/#{model_name.underscore}.rb"
if File.exists?(file_path)
inject_into_class file_path, model_name.classify do
"\n attr_accessible :email, :password, :password_confirmation if Rails::VERSION::MAJOR < 4\n" +
"\n if respond_to? :attr_accessible\n" +
"\n attr_accessible :email, :password, :password_confirmation" +
"\n end\n" +
"# Connects this user object to Blacklights Bookmarks. " +
"\n include Blacklight::User\n"
end
Expand Down

0 comments on commit 9ce2ef6

Please sign in to comment.