Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Committing user_class to master

  • Loading branch information...
commit 636383e630967c373d762ae2475f4f4e7e05f974 1 parent fe6831d
@jseitel jseitel authored
View
2  app/models/refinery/blog/post.rb
@@ -14,7 +14,7 @@ class Post < ActiveRecord::Base
default_scope :order => 'published_at DESC'
- belongs_to :author, :class_name => 'Refinery::User', :foreign_key => :user_id, :readonly => true
+ belongs_to :author, :class_name => Refinery::Blog.user_class.to_s, :foreign_key => :user_id, :readonly => true
has_many :comments, :dependent => :destroy, :foreign_key => :blog_post_id
acts_as_taggable
View
2  app/views/refinery/blog/admin/posts/_form.html.erb
@@ -94,7 +94,7 @@
<%= f.label :user_id, t('.author') %>
<%= refinery_help_tag t('.author_help') %>
<br/>
- <%= f.collection_select :user_id, ::Refinery::User.all, :id, :username %>
+ <%= f.collection_select :user_id, Refinery::Blog.user_class.all, :id, :username %>
</span>
</div>
View
3  lib/generators/refinery/blog/templates/config/initializers/refinery/blog.rb.erb
@@ -10,4 +10,7 @@ Refinery::Blog.configure do |config|
# config.share_this_key = <%= Refinery::Blog.share_this_key.inspect %>
# config.page_url = <%= Refinery::Blog.page_url.inspect %>
+
+ # If you're grafting onto an existing app, change this to your User class
+ # Refinery::Blog.user_class = <%= Refinery::Blog.user_class.inspect %>
end
View
23 lib/refinery/blog/configuration.rb
@@ -11,5 +11,28 @@ module Blog
self.post_teaser_length = 250
self.share_this_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
self.page_url = "/blog"
+
+ # Refinery::User isn't available when this line gets hit, so we use static methods instead
+ @@user_class_name = nil
+ class << self
+ def user_class=(class_name)
+ if class_name.is_a?(Class)
+ raise TypeError, "You can't set user_class to be a class, e.g., User. Instead, please use a string like 'User'"
+ elsif class_name.is_a?(String)
+ @@user_class_name = class_name
+ else
+ raise TypeError, "Invalid type for user_class. Please use a string like 'User'"
+ end
+ end
+
+ def user_class
+ class_name = @@user_class_name || 'Refinery::User'
+ begin
+ Object.const_get(class_name)
+ rescue NameError
+ class_name.constantize
+ end
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.