From 619baa9df8190579230dfcf7e5286e155d426181 Mon Sep 17 00:00:00 2001 From: Juan Quemada Date: Tue, 29 Nov 2011 07:41:11 +0100 Subject: [PATCH] Mejorar vistas de sites v2 --- app/controllers/sites_controller.rb | 7 ++++++- app/views/layouts/application.html.erb | 5 +++++ app/views/sites/_form.html.erb | 4 ++-- app/views/sites/index.html.erb | 2 +- app/views/sites/show.html.erb | 2 +- config/routes.rb | 7 ++++++- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 5deddd7..9db5a12 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -2,8 +2,13 @@ class SitesController < ApplicationController # GET /sites # GET /sites.json def index - @sites = Site.all + if params[:type_id].nil? or params[:type_id].empty? + @sites = Site.all + else + @sites = Type.find(params[:type_id]).sites + end + respond_to do |format| format.html # index.html.erb format.json { render json: @sites } diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 64eb443..c38a748 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,6 +8,11 @@ +
+ <%= link_to "Sitios", sites_path %> + <%= link_to "Tipos", types_path %> +
+ <%= yield %> diff --git a/app/views/sites/_form.html.erb b/app/views/sites/_form.html.erb index 3ec1f2f..5f8becd 100644 --- a/app/views/sites/_form.html.erb +++ b/app/views/sites/_form.html.erb @@ -17,11 +17,11 @@
<%= f.label :description %>
- <%= f.text_area :description %> + <%= f.text_area :description, :rows => 2 %>
<%= f.label :type_id %>
- <%= f.number_field :type_id %> + <%= f.collection_select(:type_id, Type.find(:all, :order => :name), :id, :name) %>
<%= f.label :latitude %>
diff --git a/app/views/sites/index.html.erb b/app/views/sites/index.html.erb index 970e447..600dd24 100644 --- a/app/views/sites/index.html.erb +++ b/app/views/sites/index.html.erb @@ -18,7 +18,7 @@ <%= site.name %> <%= site.description %> - <%= site.type_id %> + <%= site.type.name if site.type %> <%= site.latitude %> <%= site.longitude %> <%= site.zoom %> diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index cd3adb2..af3b793 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -12,7 +12,7 @@

Type: - <%= @site.type_id %> + <%= @site.type.name if @site.type %>

diff --git a/config/routes.rb b/config/routes.rb index 6c766fb..4572a56 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,12 @@ Planet::Application.routes.draw do - resources :sites + resources :sites + resources :types + + resources :types do + resources :sites + end get "planet/index"