Skip to content

Commit

Permalink
update update_role method
Browse files Browse the repository at this point in the history
  • Loading branch information
the-teacher committed Apr 4, 2012
1 parent 9bc207e commit 90755ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/controllers/admin/roles_controller.rb
Expand Up @@ -14,7 +14,9 @@ def new
@role = Role.new
end

def edit; end
def edit
#render :text => @role.to_hash and return
end

def create
@role = Role.new(params[:role])
Expand All @@ -28,7 +30,7 @@ def create
end

def update
if @role.update_role params[:role][:the_role]
if @role.update_role params[:role].try(:[],:the_role)
flash[:notice] = t('the_role.role_updated')
redirect_to edit_admin_role_path(@role)
else
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/roles/edit.html.haml
Expand Up @@ -6,6 +6,8 @@
= stylesheet_link_tag 'the_role/headers'
= stylesheet_link_tag 'the_role/form'

= new_section_admin_role_path(@role)

.the_role
%p= flash[:notice]

Expand Down
6 changes: 3 additions & 3 deletions lib/the_role/modules/role_model.rb
Expand Up @@ -62,9 +62,9 @@ def to_s
# all keys will become symbols
# look at lib/the_role/hash.rb to find definition of *underscorify_keys* method
def update_role new_role_hash
return true unless new_role_hash.instance_of? Hash
new_role = new_role_hash.underscorify_keys
role = to_hash.underscorify_keys.deep_reset
new_role_hash = new_role_hash.try(:to_hash) || {}
new_role = new_role_hash.underscorify_keys
role = to_hash.underscorify_keys.deep_reset
role.deep_merge! new_role
update_attributes(:the_role => role.to_yaml)
end
Expand Down

0 comments on commit 90755ca

Please sign in to comment.