Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Mejorar vistas de sites v2

  • Loading branch information...
commit 619baa9df8190579230dfcf7e5286e155d426181 1 parent 2705ba9
@jquemada authored
View
7 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 }
View
5 app/views/layouts/application.html.erb
@@ -8,6 +8,11 @@
</head>
<body>
+ <div>
+ <%= link_to "Sitios", sites_path %>
+ <%= link_to "Tipos", types_path %>
+ </div>
+
<%= yield %>
</body>
View
4 app/views/sites/_form.html.erb
@@ -17,11 +17,11 @@
</div>
<div class="field">
<%= f.label :description %><br />
- <%= f.text_area :description %>
+ <%= f.text_area :description, :rows => 2 %>
</div>
<div class="field">
<%= f.label :type_id %><br />
- <%= f.number_field :type_id %>
+ <%= f.collection_select(:type_id, Type.find(:all, :order => :name), :id, :name) %>
</div>
<div class="field">
<%= f.label :latitude %><br />
View
2  app/views/sites/index.html.erb
@@ -18,7 +18,7 @@
<tr>
<td><%= site.name %></td>
<td><%= site.description %></td>
- <td><%= site.type_id %></td>
+ <td><%= site.type.name if site.type %></td>
<td><%= site.latitude %></td>
<td><%= site.longitude %></td>
<td><%= site.zoom %></td>
View
2  app/views/sites/show.html.erb
@@ -12,7 +12,7 @@
<p>
<b>Type:</b>
- <%= @site.type_id %>
+ <%= @site.type.name if @site.type %>
</p>
<p>
View
7 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"
Please sign in to comment.
Something went wrong with that request. Please try again.