/
products_controller.rb
48 lines (42 loc) · 1.28 KB
/
products_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Admin
class ProductsController < Admin::PagesController
crudify :page,
:conditions => 'pages.type = "Product"',
:order => "lft ASC",
:include => [:slugs, :translations, :children],
:paging => false
def new
@page = Product.new
render :layout => false
end
def create
# Set this object as last object, given the conditions of this class.
params[:page].merge!({
:position => ((Product.maximum(:position) ||-1) + 1)
})
if (@page = Product.create(params[:page])).valid?
flash.now.notice = t(
'refinery.crudify.created',
:what => "'#{@page.title}'"
)
render :js => "parent.window.location = '#{admin_products_url}';"
else
render do |page|
message = "Ha habido errores:\n"
message << @page.errors.full_messages.map{|e| "- #{e}"}.join("\n")
page.alert(message)
end
end
end
def destroy
@page = Product.find params[:id]
@page.destroy
end
def tokens
@products = Product.with_globalize.where("title like ? and parent_id is null", "%#{params[:q]}%")
respond_to do |format|
format.json { render :json => @products }
end
end
end
end