templates/cancan.rb in prologue-0.2.0 vs templates/cancan.rb in prologue-0.3.0
- old
+ new
@@ -23,10 +23,14 @@
end
inject_into_file 'app/models/role.rb', :after => "class Role < ActiveRecord::Base\n" do
<<-RUBY
has_and_belongs_to_many :users
+
+ def self.sanitize role
+ role.to_s.humanize.split(' ').each{ |word| word.capitalize! }.join(' ')
+ end
RUBY
end
create_file 'app/models/ability.rb' do
<<-RUBY
@@ -53,16 +57,17 @@
end
end
RUBY
end
-inject_into_file 'app/models/user.rb', :before => "end\n" do
+inject_into_file 'app/models/user.rb', :before => "def destroy\n" do
<<-RUBY
def role?(role)
- return !!self.roles.find_by_name(role.to_s.camelize)
+ return !!self.roles.find_by_name( Role.sanitize role )
end
+
RUBY
end
inject_into_file 'app/controllers/application_controller.rb', :before => "end\n" do
<<-RUBY
@@ -106,11 +111,11 @@
end
end
append_file 'db/seeds.rb' do
<<-FILE
-Role.create! :name => 'Admin'.camelize
-Role.create! :name => 'Member'.camelize
+Role.create! :name => 'Admin'
+Role.create! :name => 'Member'
user1 = User.find_by_email('#{ENV['PROLOGUE_USER_EMAIL']}')
user1.role_ids = [1,2]
user1.save
FILE