Class: WcoEmail::EmailActionTemplatesController
- Inherits:
-
ApplicationController
- Object
- Wco::ApplicationController
- ApplicationController
- WcoEmail::EmailActionTemplatesController
- Defined in:
- app/controllers/wco_email/email_action_templates_controller.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
Alphabetized : ).
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
-
#update ⇒ Object
or create.
Instance Method Details
#destroy ⇒ Object
Alphabetized : )
8 9 10 11 12 13 14 |
# File 'app/controllers/wco_email/email_action_templates_controller.rb', line 8 def destroy @tmpl = WcoEmail::EmailActionTemplate.find( params[:id] ) :delete, @tmpl @tmpl.delete flash_notice 'Probably success' redirect_to action: :index end |
#edit ⇒ Object
16 17 18 19 20 |
# File 'app/controllers/wco_email/email_action_templates_controller.rb', line 16 def edit @tmpl = WcoEmail::EmailActionTemplate.find( params[:id] ) @tmpl.ties.push WcoEmail::EmailActionTemplateTie.new( next_tmpl_id: nil ) :edit, @tmpl end |
#index ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/wco_email/email_action_templates_controller.rb', line 22 def index :index, @new_tmpl if params[:deleted] @tmpls = WcoEmail::EmailActionTemplate.deleted else @tmpls = WcoEmail::EmailActionTemplate.all end if params[:q] q = URI.decode(params[:q]) @tmpls = @tmpls.where({ :slug => /#{q}/i }) end @tmpls = @tmpls.order_by( slug: :asc ) end |
#new ⇒ Object
38 39 40 |
# File 'app/controllers/wco_email/email_action_templates_controller.rb', line 38 def new :new, @new_tmpl end |
#show ⇒ Object
42 43 44 45 |
# File 'app/controllers/wco_email/email_action_templates_controller.rb', line 42 def show @tmpl = WcoEmail::EmailActionTemplate.find( params[:id] ) :show, @tmpl end |
#update ⇒ Object
or create
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/wco_email/email_action_templates_controller.rb', line 47 def update # or create puts! params, 'params' if params[:id] @tmpl = WcoEmail::EmailActionTemplate.find( params[:id] ) else @tmpl = WcoEmail::EmailActionTemplate.new end :upsert, @tmpl if params[:tmpl][:ties_attributes] params[:tmpl][:ties_attributes].each do |k, v| if !v[:next_tmpl_id].present? params[:tmpl][:ties_attributes].delete( k ) end if v[:to_delete] == "1" WcoEmail::EmailActionTemplateTie.find( v[:id] ).delete params[:tmpl][:ties_attributes].delete( k ) end end end flag = @tmpl.update_attributes( params[:tmpl].permit! ) if flag flash[:notice] = 'Success' redirect_to action: 'index' else flash[:alert] = "No luck: #{@tmpl.errors..join(', ')}. #{@tmpl.ties.map { |t| t.errors..join(', ') }.join(' | ') }" render action: 'edit' end end |