Class: MerbWords::Categories

Inherits:
Application
  • Object
show all
Defined in:
app/controllers/categories.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
# File 'app/controllers/categories.rb', line 5

def create
  display(@category = Category.new, :layout => false)
end

#create_postObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/categories.rb', line 9

def create_post
  category = Category.new(params[:category])
  if category.save
    session[:mui_message] = url(:merb_ui_message, :title => 'Category created', :tone => 'positive')
  else
    session[:mui_message] = url(:merb_ui_message, :title => 'Unable to create category', :body => mui_list(category.errors), :tone => 'negative')
    session[:mui_window] = slice_url(:category_create)
  end
  mui_window_redirect
end

#deleteObject



35
36
37
# File 'app/controllers/categories.rb', line 35

def delete
  display(@category = Category.get!(params[:category_id]), :layout => false)
end

#delete_deleteObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/categories.rb', line 39

def delete_delete
  category = Category.get!(params[:category_id])
  category.pages.clear
  category.save
  if category.destroy
    session[:mui_message] = url(:merb_ui_message, :title => 'Category deleted', :tone => 'positive')
  else
    session[:mui_message] = url(:merb_ui_message, :title => 'Unable to delete category', :body => mui_list(category.errors), :tone => 'negative')
    session[:mui_window] = slice_url(:category_delete)
  end
  mui_window_redirect
end

#updateObject



20
21
22
# File 'app/controllers/categories.rb', line 20

def update
  display(@category = Category.get!(params[:category_id]), :layout => false)
end

#update_putObject



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/categories.rb', line 24

def update_put
  category = Category.get!(params[:category_id])
  if category.update_attributes(params[:category])
    session[:mui_message] = url(:merb_ui_message, :title => 'Category updated', :tone => 'positive')
  else
    session[:mui_message] = url(:merb_ui_message, :title => 'Unable to update category', :body => mui_list(category.errors), :tone => 'negative')
    session[:mui_window] = slice_url(:category_update)
  end
  mui_window_redirect
end