Create Announcement model & controller

This commit is contained in:
Karina Kwiatek 2020-04-19 20:12:22 +01:00
parent 34604ae06f
commit 8a632a09cd
13 changed files with 96 additions and 1 deletions

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the announcement controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,20 @@
class AnnouncementController < ApplicationController
def index
@announcements = Announcement.all
end
def new
end
def create
end
def edit
end
def update
end
def destroy
end
end

View File

@ -0,0 +1,2 @@
module AnnouncementHelper
end

View File

@ -0,0 +1,2 @@
class Announcement < ApplicationRecord
end

View File

@ -0,0 +1,2 @@
<h1>Announcement#edit</h1>
<p>Find me in app/views/announcement/edit.html.erb</p>

View File

@ -0,0 +1,8 @@
- provide(:title, generate_title("Announcements"))
.container.j2-page
.row
.col-md-12
= link_to "Add new", :announcement_new, class: "btn btn-default"
- @announcements.each do |announcement|
.panel.panel-default
= announcement.content

View File

@ -0,0 +1,2 @@
<h1>Announcement#new</h1>
<p>Find me in app/views/announcement/new.html.erb</p>

View File

@ -127,5 +127,12 @@ Rails.application.routes.draw do
match '/:username/groups(/p/:page)', to: 'user#groups', via: 'get', as: :show_user_groups, defaults: {page: 1} match '/:username/groups(/p/:page)', to: 'user#groups', via: 'get', as: :show_user_groups, defaults: {page: 1}
match '/:username/questions(/p/:page)', to: 'user#questions', via: 'get', as: :show_user_questions, defaults: {page: 1} match '/:username/questions(/p/:page)', to: 'user#questions', via: 'get', as: :show_user_questions, defaults: {page: 1}
match "/admin/announcements", to: "announcement#index", via: :get, as: :announcement_index
match "/admin/announcements", to: "announcement#create", via: :post, as: :announcement_create
match "/admin/announcements/new", to: "announcement#new", via: :get, as: :announcement_new
match "/admin/announcements/:id/edit", to: "announcement#edit", via: :get, as: :announcement_edit
match "/admin/announcements/:id", to: "announcement#update", via: :patch, as: :announcement_update
match "/admin/announcements/:id", to: "announcement#destroy", via: :delete, as: :announcement_destroy
puts 'processing time of routes.rb: ' + "#{(Time.now - start).round(3).to_s.ljust(5, '0')}s".light_green puts 'processing time of routes.rb: ' + "#{(Time.now - start).round(3).to_s.ljust(5, '0')}s".light_green
end end

View File

@ -0,0 +1,14 @@
class CreateAnnouncements < ActiveRecord::Migration[5.2]
def change
create_table :announcements do |t|
t.text :content, null: false
t.string :link_text
t.string :link_href
t.datetime :starts_at, null: false
t.datetime :ends_at, null: false
t.belongs_to :user, null: false
t.timestamps
end
end
end

View File

@ -10,11 +10,23 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2016_01_05_165913) do ActiveRecord::Schema.define(version: 2020_04_19_183714) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
create_table "announcements", force: :cascade do |t|
t.text "content", null: false
t.string "link_text"
t.string "link_href"
t.datetime "starts_at", null: false
t.datetime "ends_at", null: false
t.bigint "user_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_announcements_on_user_id"
end
create_table "answers", id: :serial, force: :cascade do |t| create_table "answers", id: :serial, force: :cascade do |t|
t.text "content" t.text "content"
t.integer "question_id" t.integer "question_id"

View File

@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the AnnouncementHelper. For example:
#
# describe AnnouncementHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe AnnouncementHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Announcement, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end