templates/cancan.rb in prologue-0.1.1 vs templates/cancan.rb in prologue-0.1.2
- old
+ new
@@ -82,9 +82,29 @@
.check_box_item
= check_box_tag "user[role_ids][]", role.id, @user.roles.include?(role)
= role.name.humanize
RUBY
end
+
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "@user = User.new(params[:user])\n" do
+ <<-'RUBY'
+ @user.role_ids = params[:user][:role_ids] if current_user.role? :admin
+ RUBY
+ end
+
+ inject_into_file 'app/controllers/admin/users_controller.rb', :before => "if @user.update_attributes(params[:user])\n" do
+ <<-'RUBY'
+ @user.send(:attributes=, { :role_ids => params[:user][:role_ids] }, false) if current_user.role? :admin
+ params[:user].delete(:role_ids)
+
+ RUBY
+ end
+
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def update\n" do
+ <<-'RUBY'
+ params[:user][:role_ids] ||= []
+ RUBY
+ end
end
append_file 'db/seeds.rb' do
<<-FILE
Role.create! :name => 'Admin'.camelize