| Class | Admin::LinksController |
| In: |
app/controllers/admin/links_controller.rb
|
| Parent: | Admin::BaseController |
Controlador para la administración de enlaces externos
Listado de tags para un enlace en un auto-complete
# File app/controllers/admin/links_controller.rb, line 82
82: def auto_complete_for_link_tag_list_es
83: auto_complete_for_tag_list(params[:link][:tag_list_es])
84: if @tags.length > 0
85: render :inline => "<%= content_tag(:ul, @tags.map {|t| content_tag(:li, t.nombre)}) %>"
86: else
87: render :nothing => true
88: end
89: end
Crear nuevo enlace
# File app/controllers/admin/links_controller.rb, line 44
44: def create
45: @link = Link.new(params[:link])
46: if @link.save
47: flash[:notice] = "El enlace se ha creado correctamente"
48: redirect_to admin_links_path
49: else
50: render :action => "new"
51: end
52: end
Eliminar enlace
# File app/controllers/admin/links_controller.rb, line 71
71: def destroy
72: @link = Link.find(params[:id])
73: if @link.destroy
74: flash[:notice] = "El enlace se ha eliminado correctamente"
75: else
76: flash[:error] = "El enlace no ha podido eliminarse"
77: end
78: redirect_to admin_links_path
79: end
Modificar enlace
# File app/controllers/admin/links_controller.rb, line 55
55: def edit
56: @link = Link.find(params[:id])
57: end
Listado de enlaces
# File app/controllers/admin/links_controller.rb, line 7
7: def index
8: @sort_order = params[:sort] || "update"
9:
10: case @sort_order
11: when "update"
12: order = "updated_at DESC, title_es, published_at DESC"
13: when "publish"
14: order = "published_at DESC, title_es, updated_at DESC"
15: when "title"
16: order = "lower(tildes(title_es)), published_at DESC, updated_at DESC"
17: end
18:
19: conditions = []
20: if params[:q].present?
21: conditions << "lower(tildes(coalesce(title_es, '') || ' ' || coalesce(title_eu, ''))) like '%#{params[:q].tildes.downcase}%'"
22: end
23:
24: set_current_tab
25:
26: @links = Link.paginate :page => params[:page], :per_page => 20,
27: :order => order,
28: :conditions => conditions.join(' AND ')
29:
30: @title = t('documents.Links')
31: end
Formulario de nuevo enlace
# File app/controllers/admin/links_controller.rb, line 39
39: def new
40: @link = Link.new
41: end
Vista de un enlace
# File app/controllers/admin/links_controller.rb, line 34
34: def show
35: @link = Link.find(params[:id])
36: end
Actualizar enlace
# File app/controllers/admin/links_controller.rb, line 60
60: def update
61: @link = Link.find(params[:id])
62: if @link.update_attributes(params[:link])
63: flash[:notice] = "El enlace se ha actualizado correctamente"
64: redirect_to admin_link_path(@link)
65: else
66: render :action => "edit"
67: end
68: end