Class: Kilt::KiltController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Kilt::KiltController
- Defined in:
- app/controllers/kilt/kilt_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Post back a new object.
-
#delete ⇒ Object
Delete an object.
-
#edit ⇒ Object
View/Edit a specific object.
-
#index ⇒ Object
Show all the object types.
-
#list ⇒ Object
Show the list of items for a specific object type.
-
#new ⇒ Object
Create a new object.
-
#update ⇒ Object
Update an object.
Instance Method Details
#create ⇒ Object
Post back a new object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/kilt/kilt_controller.rb', line 34 def create type = params[:types].singularize # Get the params p = params[type] # Ensure we have a name if p['name'] == '' flash[:error] = "Name is required" redirect_to new_object_path(type.pluralize) else # Create an object and fill it with the values passed in by the form object = Kilt::Object.new(type) object.fill(p) # Call Kilt's update method if Kilt.create(object) flash[:notice] = "#{type.capitalize} successfully updated" redirect_to edit_object_path(type.pluralize, object.slug) else flash[:error] = "Couldn't save #{type.capitalize}" redirect_to new_object_path(type.pluralize) end end end |
#delete ⇒ Object
Delete an object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/kilt/kilt_controller.rb', line 98 def delete type = params[:types].singularize slug = params[:slug] object = Kilt.get(slug) # Call Kilt's update method if Kilt.delete(slug) flash[:notice] = "#{type.capitalize} successfully deleted" else flash[:error] = "Couldn't delete #{type.capitalize}" end # redirect to the list screen redirect_to list_path(type.pluralize) end |
#edit ⇒ Object
View/Edit a specific object
62 63 64 65 66 |
# File 'app/controllers/kilt/kilt_controller.rb', line 62 def edit @type = params[:types].singularize @slug = params[:slug] @object = Kilt.get(@slug) end |
#index ⇒ Object
Show all the object types
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/kilt/kilt_controller.rb', line 9 def index @types = {} type_names = Kilt.types type_names.each do |type| if Kilt.send(type).name != nil @types[type] = Kilt.send(type).name else @types[type] = type.pluralize.capitalize end end end |
#list ⇒ Object
Show the list of items for a specific object type
22 23 24 25 |
# File 'app/controllers/kilt/kilt_controller.rb', line 22 def list @type = params[:types].singularize @objects = Kilt.send(@type.pluralize).order('name') end |
#new ⇒ Object
Create a new object
28 29 30 31 |
# File 'app/controllers/kilt/kilt_controller.rb', line 28 def new @type = params[:types].singularize @object = Kilt::Object.new(@type) end |
#update ⇒ Object
Update an object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/kilt/kilt_controller.rb', line 69 def update type = params[:types].singularize slug = params[:slug] # Get the params p = params[type] # Ensure we have a name if p['name'] == '' flash[:error] = "Name is required" redirect_to edit_object_path(type.pluralize, slug) else # Create an object and fill it with the values passed in by the form object = Kilt.get(slug) object.fill(p) # Call Kilt's update method if Kilt.update(slug, object) flash[:notice] = "#{type.capitalize} successfully updated" else flash[:error] = "Couldn't save #{type.capitalize}" end # redirect to the edit screen redirect_to edit_object_path(type.pluralize, object.slug) end end |