diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb new file mode 100644 index 000000000..53545887e --- /dev/null +++ b/app/controllers/debates_controller.rb @@ -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 diff --git a/app/views/debates/_debate.html.erb b/app/views/debates/_debate.html.erb new file mode 100644 index 000000000..4f99c9df9 --- /dev/null +++ b/app/views/debates/_debate.html.erb @@ -0,0 +1,6 @@ +
+

<%= link_to debate.title, debate %>

+

<%= debate.description %>

+

Creado el: <%= l debate.created_at.to_date %>

+
+

\ No newline at end of file diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb new file mode 100644 index 000000000..98de3c538 --- /dev/null +++ b/app/views/debates/_form.html.erb @@ -0,0 +1,32 @@ +<%= form_for(@debate) do |f| %> + <% if @debate.errors.any? %> +
+

<%= pluralize(@debate.errors.count, "error") %> prohibited this debate from being saved:

+ + +
+ <% end %> + +

Título del debate

+

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!

+ <%= f.text_field :title %> + +
+

Describe tu opinión

+

Explica con todo el detalle que puedas y de una manera sencilla la idea y que crees que conseguiríamos con ella

+ <%= 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 %> + +
+ <%= f.submit %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/debates/edit.html.erb b/app/views/debates/edit.html.erb new file mode 100644 index 000000000..da5449f23 --- /dev/null +++ b/app/views/debates/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Debate

+ +<%= render 'form' %> + +<%= link_to 'Show', @debate %> | +<%= link_to 'Back', debates_path %> diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb new file mode 100644 index 000000000..ffd5803ee --- /dev/null +++ b/app/views/debates/index.html.erb @@ -0,0 +1,8 @@ +

Debates sobre Madrid

+ +
+ <%= render @debates %> +
+ +
+<%= link_to 'New Debate', new_debate_path %> diff --git a/app/views/debates/new.html.erb b/app/views/debates/new.html.erb new file mode 100644 index 000000000..c56fdb48f --- /dev/null +++ b/app/views/debates/new.html.erb @@ -0,0 +1,5 @@ +

Publicar un debate nuevo

+ +<%= render 'form' %> + +<%= link_to 'Back', debates_path %> diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb new file mode 100644 index 000000000..777b22d1b --- /dev/null +++ b/app/views/debates/show.html.erb @@ -0,0 +1,8 @@ +
+

<%= @debate.title %>

+

<%= @debate.description %>

+

Creado el: <%= l @debate.created_at.to_date %>

+
+ +<%= link_to 'Edit', edit_debate_path(@debate) %> | +<%= link_to 'Back', debates_path %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 419f31452..3e1fe0213 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,9 +6,12 @@ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> - - -<%= yield %> + +

<%= notice %>

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