forked from archan937/rich_cms
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the Rails 2 Devise based Rich-CMS admin generator (woot!)
- Loading branch information
Paul Engel
committed
Feb 5, 2011
1 parent
e405d1b
commit 5020b0f
Showing
4 changed files
with
76 additions
and
9 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
rails_generators/rich_cms_admin/lib/devise/route_devise.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Rails | ||
module Generator | ||
module Commands | ||
class Create < Base | ||
|
||
# Create devise route. Based on route_resources | ||
def route_devise(*resources) | ||
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') | ||
sentinel = 'ActionController::Routing::Routes.draw do |map|' | ||
|
||
logger.route "map.devise_for #{resource_list}" | ||
unless options[:pretend] | ||
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match| | ||
"#{match}\n map.devise_for #{resource_list}\n" | ||
end | ||
end | ||
end | ||
end | ||
|
||
class Destroy < RewindBase | ||
|
||
# Destroy devise route. Based on route_resources | ||
def route_devise(*resources) | ||
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') | ||
look_for = "\n map.devise_for #{resource_list}\n" | ||
logger.route "map.devise_for #{resource_list}" | ||
gsub_file 'config/routes.rb', /(#{look_for})/mi, '' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
rails_generators/rich_cms_admin/templates/devise/migration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Devise<%= migration_class_name %> < ActiveRecord::Migration | ||
def self.up | ||
create_table(:<%= table_name %>) do |t| | ||
t.database_authenticatable :null => false | ||
t.confirmable | ||
t.recoverable | ||
t.rememberable | ||
t.trackable | ||
# t.lockable | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :<%= table_name %>, :email, :unique => true | ||
add_index :<%= table_name %>, :confirmation_token, :unique => true | ||
add_index :<%= table_name %>, :reset_password_token, :unique => true | ||
# add_index :<%= table_name %>, :unlock_token, :unique => true | ||
end | ||
|
||
def self.down | ||
drop_table :<%= table_name %> | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class <%= model_class_name %> < ActiveRecord::Base | ||
# Include default devise modules. Others available are: | ||
# :http_authenticatable, :token_authenticatable, :confirmable, :lockable, :timeoutable and :activatable | ||
devise :registerable, :database_authenticatable, :recoverable, | ||
:rememberable, :trackable, :validatable | ||
|
||
# Setup accessible (or protected) attributes for your model | ||
attr_accessible :email, :password, :password_confirmation | ||
end |