Basic CRU operations [#5]

This commit is contained in:
rgarcia
2015-07-16 19:22:20 +02:00
parent 7ba6fc50bb
commit be342cac76
9 changed files with 111 additions and 4 deletions

View File

@@ -0,0 +1,38 @@
class DebatesController < ApplicationController
before_action :set_debate, only: [:show, :edit, :update]
def index
@debates = Debate.all
end
def show
end
def new
@debate = Debate.new
end
def edit
end
def create
@debate = Debate.create(debate_params)
respond_with @debate
end
def update
@debate.update(debate_params)
respond_with @debate
end
private
def set_debate
@debate = Debate.find(params[:id])
end
def debate_params
params.require(:debate).permit(:title, :description, :external_link, :terms_of_service)
end
end

View File

@@ -0,0 +1,6 @@
<div class='debate'>
<p><%= link_to debate.title, debate %></p>
<p><%= debate.description %></p>
<p>Creado el: <%= l debate.created_at.to_date %></p>
</div>
<br/><br/>

View File

@@ -0,0 +1,32 @@
<%= form_for(@debate) do |f| %>
<% if @debate.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@debate.errors.count, "error") %> prohibited this debate from being saved:</h2>
<ul>
<% @debate.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<p><strong>Título del debate</strong></p>
<p>Sé claro y conciso a la hora de poner un título, pero recuerda que debe explicar bien tu idea, ¡es tu carta de entrada!</p>
<%= f.text_field :title %>
<br/>
<p><strong>Describe tu opinión</strong></p>
<p>Explica con todo el detalle que puedas y de una manera sencilla la idea y que crees que conseguiríamos con ella</p>
<%= f.text_area :description %>
<% if action_name == 'new' %>
<%= f.check_box :terms_of_service %>
Acepto la política de privacidad y el aviso legal
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<br/>
<% end %>

View File

@@ -0,0 +1,6 @@
<h1>Editing Debate</h1>
<%= render 'form' %>
<%= link_to 'Show', @debate %> |
<%= link_to 'Back', debates_path %>

View File

@@ -0,0 +1,8 @@
<h1>Debates sobre Madrid</h1>
<div id='debates'>
<%= render @debates %>
</div>
<br>
<%= link_to 'New Debate', new_debate_path %>

View File

@@ -0,0 +1,5 @@
<h1>Publicar un debate nuevo</h1>
<%= render 'form' %>
<%= link_to 'Back', debates_path %>

View File

@@ -0,0 +1,8 @@
<div id="debate-<%= @debate.id %>">
<p><%= @debate.title %></p>
<p><%= @debate.description %></p>
<p>Creado el: <%= l @debate.created_at.to_date %></p>
</div>
<%= link_to 'Edit', edit_debate_path(@debate) %> |
<%= link_to 'Back', debates_path %>

View File

@@ -6,9 +6,12 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
</head> </head>
<body>
<%= yield %>
<body style="margin-left:50px">
<p id="notice"><%= notice %></p>
<div>
<%= yield %>
</div>
</body> </body>
</html> </html>

View File

@@ -3,7 +3,8 @@ Rails.application.routes.draw do
# See how all your routes lay out with "rake routes". # See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root" # You can have the root of your site routed with "root"
# root 'welcome#index' root 'welcome#index'
resources :debates
# Example of regular route: # Example of regular route:
# get 'products/:id' => 'catalog#view' # get 'products/:id' => 'catalog#view'