Permalink
Browse files

Events and places basics, closes #3

  • Loading branch information...
1 parent 062054a commit a2c3c0c0e0b8e01918d78d5356f7e6705a8b3c25 @juanignaciosl juanignaciosl committed Apr 23, 2012
@@ -0,0 +1,83 @@
+class Backend::PlacesController < BackendController
+ # GET /places
+ # GET /places.json
+ def index
+ @places = Place.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @places }
+ end
+ end
+
+ # GET /places/1
+ # GET /places/1.json
+ def show
+ @place = Place.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @place }
+ end
+ end
+
+ # GET /places/new
+ # GET /places/new.json
+ def new
+ @place = Place.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @place }
+ end
+ end
+
+ # GET /places/1/edit
+ def edit
+ @place = Place.find(params[:id])
+ end
+
+ # POST /places
+ # POST /places.json
+ def create
+ @place = Place.new(params[:place])
+
+ respond_to do |format|
+ if @place.save
+ format.html { redirect_to backend_place_url(@place), notice: 'Place was successfully created.' }
+ format.json { render json: @place, status: :created, location: @place }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @place.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /places/1
+ # PUT /places/1.json
+ def update
+ @place = Place.find(params[:id])
+
+ respond_to do |format|
+ if @place.update_attributes(params[:place])
+ format.html { redirect_to backend_place_url(@place), notice: 'Place was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @place.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /places/1
+ # DELETE /places/1.json
+ def destroy
+ @place = Place.find(params[:id])
+ @place.destroy
+
+ respond_to do |format|
+ format.html { redirect_to backend_places_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -3,8 +3,8 @@
class MgzineController < ApplicationController
def index
- @posts = PostDecorator.all
+ @posts = Post.all
- @events = EventDecorator.decorate Event.next_events
+ @events = Event.next_events
end
end
@@ -0,0 +1,2 @@
+module PlacesHelper
+end
View
@@ -0,0 +1,3 @@
+class City < ActiveRecord::Base
+ attr_accessible :name
+end
View
@@ -1,10 +1,12 @@
class Event < ActiveRecord::Base
validates :title, presence: true
- attr_accessible :end_date, :start_date, :title, :url
+ attr_accessible :end_date, :start_date, :title, :url, :place_id
belongs_to :post, :inverse_of => :event
+ belongs_to :place
+
def self.next_events
next_seven_days = Time.now.beginning_of_day .. Time.now.beginning_of_day + 7.day
View
@@ -0,0 +1,8 @@
+class Place < ActiveRecord::Base
+ attr_accessible :address, :map, :name, :url, :city_id
+
+ belongs_to :city
+
+ validates :name, :city, :presence => true
+
+end
@@ -3,7 +3,7 @@
# TODO: tests!
class PostPresenter < BasePresenter
presents :post
- delegate :title, :published_at, :body, :images, to: :post
+ delegate :title, :published_at, :body, :images, :event, to: :post
def linked_title
h.link_to post.title, post;
@@ -0,0 +1,15 @@
+<%= simple_form_for([:backend, @place],
+ html: { class: 'form-vertical' }) do |f| %>
+ <%= f.error_notification %>
+
+ <%= f.input :name %>
+
+ <%= f.association :city %>
+
+ <%= f.input :url %>
+ <%= f.input :address %>
+ <%= f.input :map %>
+
+
+ <%= f.button :submit %>
+<% end %>
@@ -0,0 +1,8 @@
+<%- title t("Edit model",
+ :model => t('activerecord.models.place'),
+ :name => @place.name) -%>
+
+<%= render 'form' %>
+
+<%= link_to t('Show'), backend_place_path(@place) %> |
+<%= link_to t('Back'), backend_places_path %>
@@ -0,0 +1,23 @@
+<h1><%= t('activerecord.models.places') %></h1>
+
+<table>
+ <tr>
+ <th><%= t(:Name) %></th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @places.each do |place| %>
+ <tr>
+ <td><%= place.name %></td>
+ <td><%= link_to t(:Show), backend_place_path(place) %></td>
+ <td><%= link_to t(:Edit), edit_backend_place_path(place) %></td>
+ <td><%= link_to t(:Destroy), backend_place_path(place), confirm: t('Are you sure?'), method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to t('New model', :model => t('activerecord.models.place')), new_backend_place_path %>
@@ -0,0 +1,5 @@
+<h1><%= t('helpers.submit.create', :model => t('activerecord.models.place') ) %></h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', backend_places_path %>
@@ -0,0 +1,34 @@
+<%- title t("Show model",
+ :model => t('activerecord.models.place'),
+ :name => @place.name) -%>
+
+<div class="row">
+ <div class="span12">
+
+ <p id="notice"><%= notice %></p>
+
+ <p>
+ <b><%= t('activerecord.attributes.place.name') %>:</b>
+ <%= @place.name %>
+ </p>
+ <p>
+ <b><%= t('activerecord.attributes.place.city') %>:</b>
+ <%= @place.city.name %>
+ </p>
+ <p>
+ <b><%= t('activerecord.attributes.place.url') %>:</b>
+ <%= @place.url %>
+ </p>
+ <p>
+ <b><%= t('activerecord.attributes.place.address') %>:</b>
+ <%= @place.address %>
+ </p>
+ <p>
+ <b><%= t('activerecord.attributes.place.map') %>:</b>
+ <%= @place.map %>
+ </p>
+
+ <%= link_to t(:Edit), edit_backend_place_path(@place) %> |
+ <%= link_to t(:Back), backend_places_path %>
+ </div>
+</div>
@@ -8,6 +8,13 @@
<%= f.input :excerpt, :as => :text %>
<%= f.association :category %>
+
+ <%= f.input :published_at %>
+
+ <%= f.simple_fields_for(:images) do |fi| %>
+ <%= fi.input :title %>
+ <%= fi.input :resource %>
+ <% end -%>
<% if @post.event.present? %>
<%= f.simple_fields_for :event do |fe| %>
@@ -16,16 +23,13 @@
<%= fe.input :title %>
<%= fe.input :start_date %>
+
+ <%= fe.association :place %>
+
</fieldset>
<% end %>
<% end %>
- <%= f.input :published_at %>
-
- <%= f.simple_fields_for(:images) do |fi| %>
- <%= fi.input :title %>
- <%= fi.input :resource %>
- <% end -%>
<%= f.button :submit %>
<% end %>
@@ -2,5 +2,5 @@
<%= render 'form' %>
-<%= link_to 'Show', backend_post_path(@post) %> |
-<%= link_to 'Back', backend_posts_path %>
+<%= link_to t('Show'), backend_post_path(@post) %> |
+<%= link_to t('Back'), backend_posts_path %>
@@ -3,7 +3,7 @@
<div class="container">
<div class="row">
<div class="span6">
- <a href="#" class="brand">Notedetengas</a>
+ <a href="/" class="brand">Notedetengas</a>
</div>
<div class="span6 user-info">
<ul class="nav">
@@ -1,7 +1,13 @@
<ul class="nav nav-tabs">
<li><a href="#">Dashboard</a></li>
- <li class="active">
- <%= link_to 'Posts', backend_posts_path %>
+
+ <!-- TODO: mark as 'active' -->
+
+ <li>
+ <%= link_to t('activerecord.models.posts'), backend_posts_path %>
+ </li>
+ <li>
+ <%= link_to t('activerecord.models.places'), backend_places_path %>
</li>
</ul>
<!-- /tabs -->
@@ -7,6 +7,14 @@
render :partial => 'events/start_date',
:locals => { :start_date => event.start_date }
end
+
%>
</a>
+
+ <%=
+ if event.place.present?
+ render :partial => 'places/place',
+ :locals => { :place => event.place }
+ end
+ %>
</div>
@@ -8,7 +8,7 @@
<% end %>
<h1>Agenda</h1>
-<% @events.each do |event| %>
+<% @events.map { |e| present e }.each do |event| %>
<section itemscope itemtype="http://schema.org/Event">
<h1><%= event.linked_title %></h1>
<%= event.start_date %>
@@ -0,0 +1,5 @@
+<div itemprop="location" itemscope itemtype="http://schema.org/Place">
+ <a itemprop="url" href="<%= place.url %>">
+ <%= place.name %>
+ </a>
+</div>
@@ -13,6 +13,12 @@
<%= presenter.body %>
</section>
+ <%=
+ if presenter.event.present?
+ render presenter.event
+ end
+ %>
+
<!-- TODO -->
View
@@ -2,4 +2,4 @@
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
- hello: "Hello world"
+ Places: "Places"
View
@@ -0,0 +1,43 @@
+es:
+ activerecord:
+
+ models:
+ place: Lugar
+ places: Lugares
+ city: Ciudad
+ cities: Ciudades
+ post: Artículo
+ posts: Artículos
+
+ attributes:
+ place:
+ name: Nombre
+ address: "Dirección"
+ map: "Plano"
+ city: Ciudad
+
+ simple_form:
+
+ labels:
+ defaults:
+ name: "Nombre"
+
+ hints:
+
+ placeholders:
+
+ helpers:
+
+ submit:
+ create: "Guardar nuevo %{model}"
+
+ Are you sure?: "¿Estás seguro?"
+
+ Show: "Ver"
+ Edit: "Editar"
+ Destroy: "Eliminar"
+ Back: "Volver"
+
+ New model: "Nuevo %{model}"
+ Edit model: "Editar %{model} %{name}"
+ Show model: "%{model} %{name}"
View
@@ -8,7 +8,7 @@
resources :posts, :only => [:show]
namespace :backend do
- resources :posts
+ resources :posts, :places
end
# TODO: route to dashboard
match 'backend' => 'backend/posts#index'
Oops, something went wrong.

0 comments on commit a2c3c0c

Please sign in to comment.