Create Announcement model & controller
This commit is contained in:
parent
34604ae06f
commit
8a632a09cd
|
@ -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/
|
|
@ -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/
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
||||||
|
module AnnouncementHelper
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
class Announcement < ApplicationRecord
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>Announcement#edit</h1>
|
||||||
|
<p>Find me in app/views/announcement/edit.html.erb</p>
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>Announcement#new</h1>
|
||||||
|
<p>Find me in app/views/announcement/new.html.erb</p>
|
|
@ -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
|
||||||
|
|
|
@ -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
|
14
db/schema.rb
14
db/schema.rb
|
@ -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"
|
||||||
|
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Announcement, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in New Issue