-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
215 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
class ApplicationController < ActionController::Base | ||
before_action :configure_permitted_parameters, if: :devise_controller? | ||
around_action :switch_locale | ||
|
||
def switch_locale(&action) | ||
I18n.with_locale(http_accept_language.compatible_language_from(I18n.available_locales), &action) | ||
end | ||
|
||
protected | ||
|
||
def configure_permitted_parameters | ||
devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class RumorsController < ApplicationController | ||
before_action :set_rumor, only: [:show, :edit, :update, :destroy] | ||
|
||
def index | ||
@rumors = Rumor.all | ||
@rumors = @rumors.search_for(params[:q]) if params[:q].present? | ||
@rumors = @rumors.page(params[:page]) | ||
end | ||
|
||
def new | ||
@rumor = Rumor.new | ||
end | ||
|
||
def create | ||
@rumor = Rumor.new(rumor_params) | ||
@rumor.user = current_user | ||
|
||
if @rumor.save | ||
redirect_to @rumor, notice: '저장하였습니다.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def show | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if @rumor.update(rumor_params) | ||
redirect_to @rumor, notice: '수정하였습니다.' | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@rumor.destroy | ||
redirect_to rumors_url | ||
end | ||
|
||
private | ||
|
||
def set_rumor | ||
@rumor = Rumor.find(params[:id]) | ||
end | ||
|
||
def rumor_params | ||
params.require(:rumor).permit( | ||
:title, :body, | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Rumor < ApplicationRecord | ||
belongs_to :user | ||
|
||
validates :title, presence: true | ||
validates :body, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
= simple_form_for @rumor do |f| | ||
= f.input :title | ||
= f.input :body, as: :summernote | ||
|
||
= f.submit data: { disable_with: "Please wait..." }, class: 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.nested-fields.border.bg-white.p-4.my-4 | ||
= f.input :title | ||
= f.input :url | ||
= f.input :body | ||
= link_to_remove_association "항목 삭제", f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.mb-4.card | ||
.card-body | ||
%h5.card-title= link_to rumor.title, rumor, class: "text-dark" | ||
|
||
%p.card-text | ||
%small= strip_tags(rumor.body).truncate(150) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
%h3.pb-2 데이터 보완하기 | ||
|
||
= render 'form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.d-flex.justify-content-between.pb-2 | ||
%h4.font-weight-bold | ||
= t('menu.rumors') | ||
- if params[:q].present? | ||
= "'#{params[:q]}'" | ||
- if user_signed_in? | ||
= link_to t('link.new_rumor'), new_rumor_path | ||
|
||
|
||
.row | ||
- @rumors.each do |rumor| | ||
.col-12 | ||
= render rumor | ||
|
||
.d-flex.justify-content-center | ||
= paginate @rumors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
%h3.pb-2 루머 추가 | ||
|
||
= render 'form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.mb-2 | ||
= link_to t('menu.rumors'), rumors_path, class: "text-dark" | ||
|
||
%h3.pb-2= @rumor.title | ||
|
||
.py-2.text-muted | ||
%span.mr-2 | ||
%i.far.fa-user | ||
= @rumor.user.name | ||
%span.mr-2 | ||
%i.far.fa-calendar | ||
= l @rumor.created_at.to_date | ||
|
||
.my-4.p-3.border.bg-white | ||
= raw @rumor.body | ||
|
||
.my-4 | ||
.d-flex.justify-content-between | ||
%div | ||
- if user_signed_in? | ||
= link_to t('link.edit'), edit_rumor_path(@rumor), class: "btn btn-outline-primary" | ||
%div | ||
- if user_signed_in? && (@rumor.user == current_user || current_user.admin?) | ||
= link_to t('link.destroy'), @rumor, method: :delete, data: { confirm: "정말 삭제하시겠습니까?" }, class: "btn btn-outline-danger" | ||
|
||
%hr | ||
|
||
.my-4 | ||
%h5.text-muted= DataSet.human_attribute_name("comments") | ||
.my-4.p-4.border.bg-white | ||
= link_to "루머에 관한 의견이 있으세요?", "https://democracy-activists.parti.xyz/p/data_activists", target: "_blank", class: "text-dark" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
devise_for :users | ||
|
||
resources :data_sets | ||
resources :rumors | ||
resources :tags | ||
|
||
root "data_sets#index" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateRumors < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :rumors do |t| | ||
t.string :title | ||
t.text :body | ||
t.belongs_to :user, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class GetUsernameFromEmail < ActiveRecord::Migration[5.2] | ||
def up | ||
User.all.each do |user| | ||
user.update(name: user.email.split('@').first) | ||
end | ||
end | ||
|
||
def down | ||
User.all.each do |user| | ||
user.update(name: nil) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
title: MyString | ||
body: MyText | ||
|
||
two: | ||
title: MyString | ||
body: MyText |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class RumorTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |