I have this code in my r_grids_controller.rb
before_filter -> {find_rgrid_by_user params[:user_id]}, only: [:update_admin_call, :update_admin_email,
:update_admin_offline, :update_onboarded]
.........
def update_admin_email
old_admin_email = @rgrid.admin_email
@rgrid.update_attribute('admin_email', !old_admin_email)
respond_to do |format|
format.js { render 'update_checkbox', :locals => {:checkbox_name => "email_#{params[:user_id]}"}}
end
end
def update_admin_call
old_admin_call = @rgrid.admin_call
@rgrid.update_attribute('admin_call', !old_admin_call)
respond_to do |format|
format.js { render 'update_checkbox', :locals => {:checkbox_name => "call_#{params[:user_id]}"}}
end
end
def update_admin_offline
old_admin_offline = @rgrid.admin_offline
@rgrid.update_attribute('admin_offline', !old_admin_offline)
respond_to do |format|
format.js { render 'update_checkbox', :locals => {:checkbox_name => "offline_#{params[:user_id]}"}}
end
end
def update_onboarded
old_onboarded = @rgrid.onboarded
@rgrid.update_attribute('onboarded', !old_onboarded)
respond_to do |format|
format.js { render 'update_checkbox', :locals => {:checkbox_name => "onboarded_#{params[:user_id]}"}}
end
end
private
def find_rgrid_by_user(user_id)
@rgrid = RGrid.find_by_user_id(user_id)
end
using RubyCritic, it says me that these 4 blocks are 'DuplicateCode'. However, I don't know how can I refactor this to keep it DRY.
Somebody has an idea? :-)
Aucun commentaire:
Enregistrer un commentaire