Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Old ConfigTemplateController#update:
- def update
- @config_template = ConfigTemplate.find(params[:id])
- respond_to do |format|
- if @config_template.update_attributes(params[:config_template])
- format.html do
- notice "Successfully updated config template."
- redirect_to config_templates_url
- end
- format.json {render :json => @config_template, :status => :ok}
- else
- format.html {render :action => 'edit'}
- format.json {render :json => @config_template.errors, :status => :unprocessable_entity}
- end
- end
- end
- New ConfigTemplateController#update:
- def update
- @config_template = ConfigTemplate.find(params[:id])
- if @config_template.update_attributes(params[:config_template])
- process_success @config_template, "Successfully updated config template.", config_templates_url
- else
- process_error @config_template, :render =>"edit"
- end
- end
- New methods in application_controller:
- def process_success object, success_msg, success_redirect, json_code = :ok
- respond_to do |format|
- format.html do
- notice success_msg
- redirect_to success_redirect
- end
- format.json { render :json => object, :status => json_code}
- end
- end
- def process_error object, hash
- hash[:json_code] ||= :unprocessable_entity
- respond_to do |format|
- format.html do
- error hash[:error_msg] if hash[:error_msg]
- render :action => hash[:render] if hash[:render]
- redirect_to hash[:redirect] if hash[:redirect]
- end
- format.json { render :json => object.errors, :status => hash[:json_code]}
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement