Basic CRU operations [#5]
This commit is contained in:
38
app/controllers/debates_controller.rb
Normal file
38
app/controllers/debates_controller.rb
Normal 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
|
||||
6
app/views/debates/_debate.html.erb
Normal file
6
app/views/debates/_debate.html.erb
Normal 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/>
|
||||
32
app/views/debates/_form.html.erb
Normal file
32
app/views/debates/_form.html.erb
Normal 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 %>
|
||||
6
app/views/debates/edit.html.erb
Normal file
6
app/views/debates/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<h1>Editing Debate</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @debate %> |
|
||||
<%= link_to 'Back', debates_path %>
|
||||
8
app/views/debates/index.html.erb
Normal file
8
app/views/debates/index.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<h1>Debates sobre Madrid</h1>
|
||||
|
||||
<div id='debates'>
|
||||
<%= render @debates %>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<%= link_to 'New Debate', new_debate_path %>
|
||||
5
app/views/debates/new.html.erb
Normal file
5
app/views/debates/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>Publicar un debate nuevo</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', debates_path %>
|
||||
8
app/views/debates/show.html.erb
Normal file
8
app/views/debates/show.html.erb
Normal 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 %>
|
||||
@@ -6,9 +6,12 @@
|
||||
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
<body style="margin-left:50px">
|
||||
<p id="notice"><%= notice %></p>
|
||||
<div>
|
||||
<%= yield %>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user