Class | Cms::ResourceController |
In: |
app/controllers/cms/resource_controller.rb
|
Parent: | Cms::BaseController |
This is meant to be extended by other controller Provides basic Restful CRUD
# File app/controllers/cms/resource_controller.rb, line 13 13: def create 14: @object = build_object(params[variable_name]) 15: if @object.save 16: flash[:notice] = "#{resource_name.singularize.titleize} '#{object_name}' was created" 17: redirect_to after_create_url 18: else 19: instance_variable_set("@#{variable_name}", @object) 20: if (params[:on_fail_action]) 21: render :action => params[:on_fail_action] 22: else 23: render :action => 'new' 24: end 25: end 26: end
# File app/controllers/cms/resource_controller.rb, line 51 51: def destroy 52: @object = resource.find(params[:id]) 53: if @object.destroy 54: flash[:notice] = "#{resource_name.singularize.titleize} '#{object_name}' was deleted" 55: end 56: redirect_to index_url 57: end
# File app/controllers/cms/resource_controller.rb, line 32 32: def edit 33: instance_variable_set("@#{variable_name}", resource.find(params[:id])) 34: end
# File app/controllers/cms/resource_controller.rb, line 5 5: def index 6: instance_variable_set("@#{variable_name.pluralize}", resource.all(:order => order_by_column)) 7: end
# File app/controllers/cms/resource_controller.rb, line 9 9: def new 10: instance_variable_set("@#{variable_name}", build_object) 11: end
# File app/controllers/cms/resource_controller.rb, line 28 28: def show 29: instance_variable_set("@#{variable_name}", resource.find(params[:id])) 30: end
# File app/controllers/cms/resource_controller.rb, line 36 36: def update 37: @object = resource.find(params[:id]) 38: if @object.update_attributes(params[variable_name]) 39: flash[:notice] = "#{resource_name.singularize.titleize} '#{object_name}' was updated" 40: redirect_to after_update_url 41: else 42: instance_variable_set("@#{variable_name}", @object) 43: if (params[:on_fail_action]) 44: render :action => params[:on_fail_action] 45: else 46: render :action => 'edit' 47: end 48: end 49: end
# File app/controllers/cms/resource_controller.rb, line 85 85: def after_create_url 86: show_url 87: end
# File app/controllers/cms/resource_controller.rb, line 89 89: def after_update_url 90: show_url 91: end
# File app/controllers/cms/resource_controller.rb, line 72 72: def build_object(params={}) 73: resource.new(params) 74: end
# File app/controllers/cms/resource_controller.rb, line 104 104: def edit_template; 105: 'cms/blocks/edit' 106: end
# File app/controllers/cms/resource_controller.rb, line 81 81: def index_url 82: cms_index_url_for(resource_name) 83: end
# File app/controllers/cms/resource_controller.rb, line 101 101: def new_template; 102: 'cms/blocks/new' 103: end
# File app/controllers/cms/resource_controller.rb, line 76 76: def object_name 77: return nil unless @object 78: @object.respond_to?(:name) ? @object.name : @object.to_s 79: end
# File app/controllers/cms/resource_controller.rb, line 97 97: def order_by_column 98: "name" 99: end
# File app/controllers/cms/resource_controller.rb, line 68 68: def resource 69: resource_name.classify.constantize 70: end
# File app/controllers/cms/resource_controller.rb, line 60 60: def resource_name 61: controller_name 62: end
# File app/controllers/cms/resource_controller.rb, line 93 93: def show_url 94: [:cms, @object] 95: end