From 996e87cb1382761a9a835d86a1f480dea85a0969 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 15 Dec 2015 13:08:03 +0100 Subject: [PATCH] adds legislations --- app/controllers/legislations_controller.rb | 8 ++++++++ app/models/annotation.rb | 2 +- app/models/legislation.rb | 3 +++ app/views/legislations/show.html.erb | 10 ++++++++++ config/routes.rb | 2 ++ db/migrate/20151215113827_create_legislations.rb | 10 ++++++++++ db/schema.rb | 7 +++++++ 7 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 app/controllers/legislations_controller.rb create mode 100644 app/models/legislation.rb create mode 100644 app/views/legislations/show.html.erb create mode 100644 db/migrate/20151215113827_create_legislations.rb diff --git a/app/controllers/legislations_controller.rb b/app/controllers/legislations_controller.rb new file mode 100644 index 000000000..a95f95ef2 --- /dev/null +++ b/app/controllers/legislations_controller.rb @@ -0,0 +1,8 @@ +class LegislationsController < ApplicationController + load_and_authorize_resource + + def show + @legislation = Legislation.find(params[:id]) + end + +end \ No newline at end of file diff --git a/app/models/annotation.rb b/app/models/annotation.rb index b747efd3b..504232c36 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -1,6 +1,6 @@ class Annotation < ActiveRecord::Base serialize :ranges, Array - belongs_to :proposal + belongs_to :legislation belongs_to :user end \ No newline at end of file diff --git a/app/models/legislation.rb b/app/models/legislation.rb new file mode 100644 index 000000000..d918c0255 --- /dev/null +++ b/app/models/legislation.rb @@ -0,0 +1,3 @@ +class Legislation < ActiveRecord::Base + has_many :annotations +end diff --git a/app/views/legislations/show.html.erb b/app/views/legislations/show.html.erb new file mode 100644 index 000000000..a1da0a060 --- /dev/null +++ b/app/views/legislations/show.html.erb @@ -0,0 +1,10 @@ +<% if current_user %> +
data-user-id=<%= current_user.id %>> +<% else %> +
+<% end %> + +
<%= @legislation.title %>
+
<%= @legislation.body %>
+ +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5f016ee0c..3472f1c4e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,6 +61,8 @@ Rails.application.routes.draw do end end + resources :legislations, only: [:show] + resources :annotations do collection do get :search diff --git a/db/migrate/20151215113827_create_legislations.rb b/db/migrate/20151215113827_create_legislations.rb new file mode 100644 index 000000000..5ea4ff5be --- /dev/null +++ b/db/migrate/20151215113827_create_legislations.rb @@ -0,0 +1,10 @@ +class CreateLegislations < ActiveRecord::Migration + def change + create_table :legislations do |t| + t.string :title + t.text :body + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a19695fae..c46d99fd7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -181,6 +181,13 @@ ActiveRecord::Schema.define(version: 20151118160928) do add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree + create_table "legislations", force: :cascade do |t| + t.string "title" + t.text "body" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "locks", force: :cascade do |t| t.integer "user_id" t.integer "tries", default: 0