Class: Admin::FormsController
- Inherits:
-
Noodall::Admin::BaseController
- Object
- Noodall::Admin::BaseController
- Admin::FormsController
- Includes:
- SortableTable::App::Controllers::ApplicationController
- Defined in:
- app/controllers/noodall/admin/forms_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/noodall/admin/forms_controller.rb', line 36 def create # convert hashes with stringy integer keys to an array of hashes params[:form][:fields] = params[:form][:fields].sort{|a,b| a.first.to_i <=> b.first.to_i }.map{|item| item.last } @form = Noodall::Form.new(params[:form]) respond_to do |format| if @form.save flash[:notice] = "Form was successfully created." format.html { redirect_to noodall_admin_forms_path } format.xml { render :xml => @form, :status => :created } else format.html do render :action => "show" end format.xml { render :xml => @form.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/noodall/admin/forms_controller.rb', line 78 def destroy @form = Noodall::Form.find(params[:id]) @form.destroy flash[:notice] = "Form was successfully deleted." respond_to do |format| format.html { redirect_to(noodall_admin_forms_url) } format.xml { head :ok } end end |
#index ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'app/controllers/noodall/admin/forms_controller.rb', line 8 def index @forms = Noodall::Form.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @forms } end end |
#new ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/noodall/admin/forms_controller.rb', line 26 def new @form = Noodall::Form.new @form.create_mandatory_fields! respond_to do |format| format.html { render :action => "show" } format.xml { render :xml => @form } end end |
#show ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/controllers/noodall/admin/forms_controller.rb', line 17 def show @form = Noodall::Form.find(params[:id]) respond_to do |format| format.html format.xml { render :xml => @form } end end |
#update ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/noodall/admin/forms_controller.rb', line 56 def update # convert hashes with stringy integer keys to an array of hashes params[:form][:fields] = params[:form][:fields].sort{|a,b| a.first.to_i <=> b.first.to_i }.map{|item| item.last } logger.debug(params[:form][:fields].inspect) @form = Noodall::Form.find(params[:id]) respond_to do |format| if @form.update_attributes(params[:form]) flash[:notice] = "Form was successfully updated." format.html { redirect_to noodall_admin_forms_path } format.xml { head :ok } else format.html { render :action => "show" } format.xml { render :xml => @form.errors, :status => :unprocessable_entity } end end end |