Skip to content

Commit

Permalink
Remove duplcation about update settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Francois committed Aug 12, 2013
1 parent 513d482 commit 7be482e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
8 changes: 8 additions & 0 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ def insert_editor

private

def update_settings_with!(params)
Blog.transaction do
params[:setting].each { |k,v| this_blog.send("#{k.to_s}=", v) }
this_blog.save
flash[:notice] = _('config updated.')
end
end

def save_a(object, title)
if object.save
flash[:notice] = _("#{title.capitalize} was successfully saved.")
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/admin/seo_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ def update_settings
if params[:setting]['permalink_format'] and params[:setting]['permalink_format'] == 'custom'
params[:setting]['permalink_format'] = params[:setting]['custom_permalink']
end
Blog.transaction do
params[:setting].each { |k,v| this_blog.send("#{k.to_s}=", v) }
this_blog.save
flash[:notice] = _('config updated.')
end
update_settings_with!(params)
if params[:setting][:robots].present?
Robot.new.add(params[:setting][:robots])
end
Expand Down
11 changes: 3 additions & 8 deletions app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@ def index

def write; load_settings end
def feedback; load_settings end

def redirect
flash[:notice] = _("Please review and save the settings before continuing")
redirect_to :action => "index"
end

def update
if request.post?
Blog.transaction do
params[:setting].each { |k,v| this_blog.send("#{k.to_s}=", v) }
this_blog.save
flash[:notice] = _('config updated.')
end

redirect_to :action => params[:from]
update_settings_with!(params)
redirect_to action: params[:from]
end
rescue ActiveRecord::RecordInvalid
render params[:from]
Expand Down

0 comments on commit 7be482e

Please sign in to comment.