diff --git a/.gitignore b/.gitignore index 7016af9..4a78c9f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,8 +16,14 @@ /public/uploads/* # Ignore configs -mongoid.yml +/config/mongoid.yml /config/credentials/*.yml +.env +/config/nginx.conf # Ignore DS_Store .DS_Store + +# Ignore assets +/public/assets + diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..005119b --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.4.1 diff --git a/Capfile b/Capfile index d30f46a..948e2b6 100644 --- a/Capfile +++ b/Capfile @@ -1,3 +1,15 @@ -load 'deploy' -load 'deploy/assets' -load 'config/deploy' # remove this line to skip loading any of the default tasks \ No newline at end of file +require "capistrano/setup" +require "capistrano/deploy" + +require "capistrano/scm/git" +install_plugin Capistrano::SCM::Git + +require "capistrano/rbenv" +require "capistrano/bundler" +require "capistrano/rails/assets" +require "capistrano/puma" + +install_plugin Capistrano::Puma + +# Load custom tasks from `lib/capistrano/tasks` if you have any defined +Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } diff --git a/Gemfile b/Gemfile index 85a44ff..f4d82ec 100644 --- a/Gemfile +++ b/Gemfile @@ -1,19 +1,18 @@ source 'https://rubygems.org' +ruby '2.4.1' -gem 'rails', '3.2.9' - -# Bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' +gem 'rails', '4.2.8' # db -gem 'mongoid' +gem 'mongoid', '4.0.2' +gem 'mongoid-observers', '0.2.0' gem 'geocoder' # file upload -gem 'rmagick' -gem 'carrierwave' +gem 'mini_magick' +gem 'carrierwave', '~> 1.0' gem 'carrierwave-mongoid', require: 'carrierwave/mongoid' -gem "fog" +gem 'fog-aws', '0.12.0' # auth gem 'devise' @@ -24,31 +23,38 @@ gem 'omniauth-twitter' gem 'koala' gem 'twitter' -# Gems used only for assets and not required -# in production environments by default. -group :assets do - gem 'sass-rails', '~> 3.2.3' - gem 'coffee-rails', '~> 3.2.1' - gem 'uglifier', '>= 1.0.3' - gem "therubyracer" - gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS - gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git' -end +gem 'sass-rails' +gem 'coffee-rails' +gem 'uglifier' +gem 'therubyracer', '~>0.12.3' +gem 'less-rails', '~>2.8.0' +gem 'twitter-bootstrap-rails', '2.2.8' gem 'jquery-rails' gem 'simple_form' -# To use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.0.0' - -# To use Jbuilder templates for JSON gem 'jbuilder' -# Use unicorn as the app server -# gem 'unicorn' +gem 'jquery-countdown-rails' + +gem 'dotenv-rails' +gem 'puma' -# Deploy with Capistrano -gem 'capistrano' +group :development, :test do + gem 'pry-byebug' + gem 'spring' + gem 'railroady' +end + +group :development do + gem 'web-console', '~> 2.0' + gem 'capistrano', '~> 3.8' + gem 'capistrano-rbenv', require: false + gem 'capistrano-rails', require: false + gem 'capistrano-bundler', require: false + gem 'capistrano3-puma', require: false +end -# To use debugger -# gem 'debugger' +group :production do + gem 'rails_12factor' +end diff --git a/Gemfile.lock b/Gemfile.lock index ab1c288..56c825f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,240 +1,369 @@ -GIT - remote: git://github.com/seyhunak/twitter-bootstrap-rails.git - revision: 7d2b3093f654d193f55b6d96e806bc4b2e1bcb93 - specs: - twitter-bootstrap-rails (2.1.7) - actionpack (>= 3.1) - execjs - railties (>= 3.1) - GEM remote: https://rubygems.org/ specs: - actionmailer (3.2.9) - actionpack (= 3.2.9) - mail (~> 2.4.4) - actionpack (3.2.9) - activemodel (= 3.2.9) - activesupport (= 3.2.9) - builder (~> 3.0.0) + actionmailer (4.2.8) + actionpack (= 4.2.8) + actionview (= 4.2.8) + activejob (= 4.2.8) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.8) + actionview (= 4.2.8) + activesupport (= 4.2.8) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.8) + activesupport (= 4.2.8) + builder (~> 3.1) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.0) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.9) - activesupport (= 3.2.9) - builder (~> 3.0.0) - activerecord (3.2.9) - activemodel (= 3.2.9) - activesupport (= 3.2.9) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.9) - activemodel (= 3.2.9) - activesupport (= 3.2.9) - activesupport (3.2.9) - i18n (~> 0.6) - multi_json (~> 1.0) - addressable (2.3.2) - arel (3.0.2) - bcrypt-ruby (3.0.1) - builder (3.0.4) - capistrano (2.13.5) - highline - net-scp (>= 1.0.0) - net-sftp (>= 2.0.0) - net-ssh (>= 2.0.14) - net-ssh-gateway (>= 1.1.0) - carrierwave (0.6.2) - activemodel (>= 3.2.0) - activesupport (>= 3.2.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (4.2.8) + activesupport (= 4.2.8) + globalid (>= 0.3.0) + activemodel (4.2.8) + activesupport (= 4.2.8) + builder (~> 3.1) + activerecord (4.2.8) + activemodel (= 4.2.8) + activesupport (= 4.2.8) + arel (~> 6.0) + activesupport (4.2.8) + i18n (~> 0.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + addressable (2.5.1) + public_suffix (~> 2.0, >= 2.0.2) + airbrussh (1.2.0) + sshkit (>= 1.6.1, != 1.7.0) + arel (6.0.4) + bcrypt (3.1.11) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + bson (3.2.6) + buftok (0.2.0) + builder (3.2.3) + byebug (9.0.6) + capistrano (3.8.1) + airbrussh (>= 1.0.0) + i18n + rake (>= 10.0.0) + sshkit (>= 1.9.0) + capistrano-bundler (1.2.0) + capistrano (~> 3.1) + sshkit (~> 1.2) + capistrano-rails (1.2.3) + capistrano (~> 3.1) + capistrano-bundler (~> 1.1) + capistrano-rbenv (2.1.1) + capistrano (~> 3.1) + sshkit (~> 1.3) + capistrano3-puma (3.1.0) + capistrano (~> 3.7) + capistrano-bundler + puma (~> 3.4) + carrierwave (1.1.0) + activemodel (>= 4.0.0) + activesupport (>= 4.0.0) + mime-types (>= 1.16) carrierwave-mongoid (0.1.0) carrierwave mongoid - coffee-rails (3.2.2) + coderay (1.1.1) + coffee-rails (4.2.1) coffee-script (>= 2.2.0) - railties (~> 3.2.0) - coffee-script (2.2.0) + railties (>= 4.0.0, < 5.2.x) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.4.0) - commonjs (0.2.6) - devise (2.1.2) - bcrypt-ruby (~> 3.0) + coffee-script-source (1.12.2) + commonjs (0.2.7) + concurrent-ruby (1.0.5) + connection_pool (2.2.1) + debug_inspector (0.0.2) + devise (4.2.1) + bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (~> 3.1) - warden (~> 1.2.1) + railties (>= 4.1.0, < 5.1) + responders + warden (~> 1.2.3) + domain_name (0.5.20170404) + unf (>= 0.0.5, < 1.0.0) + dotenv (2.2.1) + dotenv-rails (2.2.1) + dotenv (= 2.2.1) + railties (>= 3.2, < 5.2) + equalizer (0.0.11) erubis (2.7.0) - excon (0.13.4) - execjs (1.4.0) - multi_json (~> 1.0) - faraday (0.8.4) - multipart-post (~> 1.1) - fog (1.3.1) + excon (0.55.0) + execjs (2.7.0) + faraday (0.11.0) + multipart-post (>= 1.2, < 3) + fog-aws (0.12.0) + fog-core (~> 1.38) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) + fog-core (1.44.1) builder - excon (~> 0.13.0) - formatador (~> 0.2.0) - mime-types - multi_json (~> 1.0) - net-scp (~> 1.0.4) - net-ssh (>= 2.1.3) - nokogiri (~> 1.5.0) - ruby-hmac - formatador (0.2.3) - geocoder (1.1.3) - hashie (1.2.0) - highline (1.6.15) - hike (1.2.1) - httpauth (0.2.0) - i18n (0.6.1) - jbuilder (0.8.2) - activesupport (>= 3.0.0) - journey (1.0.4) - jquery-rails (2.1.3) - railties (>= 3.1.0, < 5.0) - thor (~> 0.14) - json (1.7.5) - jwt (0.1.5) - multi_json (>= 1.0) - koala (1.6.0) - addressable (~> 2.2) - faraday (~> 0.8) + excon (~> 0.49) + formatador (~> 0.2) + fog-json (1.0.2) + fog-core (~> 1.0) + multi_json (~> 1.10) + fog-xml (0.1.3) + fog-core + nokogiri (>= 1.5.11, < 2.0.0) + formatador (0.2.5) + geocoder (1.4.3) + globalid (0.4.0) + activesupport (>= 4.2.0) + hashie (3.5.5) + http (2.2.2) + addressable (~> 2.3) + http-cookie (~> 1.0) + http-form_data (~> 1.0.1) + http_parser.rb (~> 0.6.0) + http-cookie (1.0.3) + domain_name (~> 0.5) + http-form_data (1.0.2) + http_parser.rb (0.6.0) + i18n (0.8.1) + ipaddress (0.8.3) + jbuilder (2.6.3) + activesupport (>= 3.0.0, < 5.2) + multi_json (~> 1.2) + jquery-countdown-rails (2.0.2) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (2.1.0) + jwt (1.5.6) + koala (3.0.0) + addressable + faraday + json (>= 1.8) + less (2.6.0) + commonjs (~> 0.2.7) + less-rails (2.8.0) + actionpack (>= 4.0) + less (~> 2.6.0) + sprockets (> 2, < 4) + tilt + libv8 (3.16.14.19) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.5) + mime-types (>= 1.16, < 4) + memoizable (0.4.2) + thread_safe (~> 0.3, >= 0.3.1) + method_source (0.8.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_magick (4.7.0) + mini_portile2 (2.1.0) + minitest (5.10.1) + mongoid (4.0.2) + activemodel (~> 4.0) + moped (~> 2.0.0) + origin (~> 2.1) + tzinfo (>= 0.3.37) + mongoid-observers (0.2.0) + mongoid (>= 4.0.0) + rails-observers (~> 0.1.2) + moped (2.0.7) + bson (~> 3.0) + connection_pool (~> 2.0) + optionable (~> 0.2.0) + multi_json (1.12.1) + multi_xml (0.6.0) + multipart-post (2.0.0) + naught (1.1.0) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (4.1.0) + nokogiri (1.7.1) + mini_portile2 (~> 2.1.0) + oauth (0.5.1) + oauth2 (1.3.1) + faraday (>= 0.8, < 0.12) + jwt (~> 1.0) multi_json (~> 1.3) - less (2.2.2) - commonjs (~> 0.2.6) - less-rails (2.2.6) - actionpack (>= 3.1) - less (~> 2.2.0) - libv8 (3.3.10.4) - mail (2.4.4) - i18n (>= 0.4.0) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.19) - mongoid (3.0.6) - activemodel (~> 3.1) - moped (~> 1.1) - origin (~> 1.0) - tzinfo (~> 0.3.22) - moped (1.2.8) - multi_json (1.4.0) - multipart-post (1.1.5) - net-scp (1.0.4) - net-ssh (>= 1.99.1) - net-sftp (2.0.5) - net-ssh (>= 2.0.9) - net-ssh (2.6.1) - net-ssh-gateway (1.1.0) - net-ssh (>= 1.99.1) - nokogiri (1.5.5) - oauth (0.4.7) - oauth2 (0.8.0) - faraday (~> 0.8) - httpauth (~> 0.1) - jwt (~> 0.1.4) - multi_json (~> 1.0) - rack (~> 1.2) - omniauth (1.1.1) - hashie (~> 1.2) - rack - omniauth-facebook (1.4.1) - omniauth-oauth2 (~> 1.1.0) - omniauth-oauth (1.0.1) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.6.1) + hashie (>= 3.4.6, < 3.6.0) + rack (>= 1.6.2, < 3) + omniauth-facebook (4.0.0) + omniauth-oauth2 (~> 1.2) + omniauth-oauth (1.1.0) oauth omniauth (~> 1.0) - omniauth-oauth2 (1.1.1) - oauth2 (~> 0.8.0) - omniauth (~> 1.0) - omniauth-twitter (0.0.14) - multi_json (~> 1.3) - omniauth-oauth (~> 1.0) - origin (1.0.10) - orm_adapter (0.4.0) - polyglot (0.3.3) - rack (1.4.1) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.2) + omniauth-oauth2 (1.4.0) + oauth2 (~> 1.0) + omniauth (~> 1.2) + omniauth-twitter (1.4.0) + omniauth-oauth (~> 1.1) rack - rack-test (0.6.2) + optionable (0.2.0) + origin (2.3.0) + orm_adapter (0.5.0) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-byebug (3.4.2) + byebug (~> 9.0) + pry (~> 0.10) + public_suffix (2.0.5) + puma (3.8.2) + rack (1.6.5) + rack-test (0.6.3) rack (>= 1.0) - rails (3.2.9) - actionmailer (= 3.2.9) - actionpack (= 3.2.9) - activerecord (= 3.2.9) - activeresource (= 3.2.9) - activesupport (= 3.2.9) - bundler (~> 1.0) - railties (= 3.2.9) - railties (3.2.9) - actionpack (= 3.2.9) - activesupport (= 3.2.9) - rack-ssl (~> 1.3.2) + railroady (1.5.2) + rails (4.2.8) + actionmailer (= 4.2.8) + actionpack (= 4.2.8) + actionview (= 4.2.8) + activejob (= 4.2.8) + activemodel (= 4.2.8) + activerecord (= 4.2.8) + activesupport (= 4.2.8) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.8) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.8) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + rails-observers (0.1.2) + activemodel (~> 4.0) + rails_12factor (0.0.3) + rails_serve_static_assets + rails_stdout_logging + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) + railties (4.2.8) + actionpack (= 4.2.8) + activesupport (= 4.2.8) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) - rake (10.0.2) - rdoc (3.12) - json (~> 1.4) - rmagick (2.13.1) - ruby-hmac (0.4.0) - sass (3.2.3) - sass-rails (3.2.5) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) - simple_form (2.0.4) - actionpack (~> 3.0) - activemodel (~> 3.0) - simple_oauth (0.2.0) - sprockets (2.2.2) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - therubyracer (0.10.2) - libv8 (~> 3.3.10) - thor (0.16.0) - tilt (1.3.3) - treetop (1.4.12) - polyglot - polyglot (>= 0.3.1) - twitter (4.4.1) - faraday (~> 0.8) - multi_json (~> 1.3) - simple_oauth (~> 0.2) - tzinfo (0.3.35) - uglifier (1.3.0) - execjs (>= 0.3.0) - multi_json (~> 1.0, >= 1.0.2) - warden (1.2.1) + thor (>= 0.18.1, < 2.0) + rake (12.0.0) + ref (2.0.0) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) + sass (3.4.23) + sass-rails (5.0.6) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + simple_form (3.4.0) + actionpack (> 4, < 5.1) + activemodel (> 4, < 5.1) + simple_oauth (0.3.1) + slop (3.6.0) + spring (2.0.1) + activesupport (>= 4.2) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.0) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sshkit (1.13.1) + net-scp (>= 1.1.2) + net-ssh (>= 2.8.0) + therubyracer (0.12.3) + libv8 (~> 3.16.14.15) + ref + thor (0.19.4) + thread_safe (0.3.6) + tilt (2.0.7) + twitter (6.1.0) + addressable (~> 2.5) + buftok (~> 0.2.0) + equalizer (= 0.0.11) + faraday (~> 0.11.0) + http (~> 2.1) + http_parser.rb (~> 0.6.0) + memoizable (~> 0.4.2) + naught (~> 1.1) + simple_oauth (~> 0.3.1) + twitter-bootstrap-rails (2.2.8) + actionpack (>= 3.1) + execjs + rails (>= 3.1) + railties (>= 3.1) + tzinfo (1.2.3) + thread_safe (~> 0.1) + uglifier (3.2.0) + execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.4) + warden (1.2.7) rack (>= 1.0) + web-console (2.3.0) + activemodel (>= 4.0) + binding_of_caller (>= 0.7.2) + railties (>= 4.0) + sprockets-rails (>= 2.0, < 4.0) PLATFORMS ruby DEPENDENCIES - capistrano - carrierwave + capistrano (~> 3.8) + capistrano-bundler + capistrano-rails + capistrano-rbenv + capistrano3-puma + carrierwave (~> 1.0) carrierwave-mongoid - coffee-rails (~> 3.2.1) + coffee-rails devise - fog + dotenv-rails + fog-aws (= 0.12.0) geocoder jbuilder + jquery-countdown-rails jquery-rails koala - less-rails - mongoid + less-rails (~> 2.8.0) + mini_magick + mongoid (= 4.0.2) + mongoid-observers (= 0.2.0) omniauth-facebook omniauth-twitter - rails (= 3.2.9) - rmagick - sass-rails (~> 3.2.3) + pry-byebug + puma + railroady + rails (= 4.2.8) + rails_12factor + sass-rails simple_form - therubyracer + spring + therubyracer (~> 0.12.3) twitter - twitter-bootstrap-rails! - uglifier (>= 1.0.3) + twitter-bootstrap-rails (= 2.2.8) + uglifier + web-console (~> 2.0) + +RUBY VERSION + ruby 2.4.1p111 + +BUNDLED WITH + 1.14.6 diff --git a/README.md b/README.md new file mode 100644 index 0000000..89d8bca --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +투표 대잔치 +======== + +### 설치 + +* ruby 2 +* rails 4.2 +* mongoid 4.0.2 +* mongoid-observers 0.2.0 + + +### 실행 + +* 환경변수 + * MONGODB + - 예) mongodb://USER_NAME:PASSWORD@mongodburl.com:PORT/DATA + * omniauth login + * TWITTER_KEY + * TWITTER_SECRET + * FACEBOOK_KEY + * FACEBOOK_SECRET + * image file upload + * AWS_KEY + * AWS_SECRET + * AWS_BUCKET + + +### 배포 + +* Capistrano + * SERVER + * REPO + * BRANCH + * DEPLOYER diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index 7c36f23..0000000 --- a/README.rdoc +++ /dev/null @@ -1,261 +0,0 @@ -== Welcome to Rails - -Rails is a web-application framework that includes everything needed to create -database-backed web applications according to the Model-View-Control pattern. - -This pattern splits the view (also called the presentation) into "dumb" -templates that are primarily responsible for inserting pre-built data in between -HTML tags. The model contains the "smart" domain objects (such as Account, -Product, Person, Post) that holds all the business logic and knows how to -persist themselves to a database. The controller handles the incoming requests -(such as Save New Account, Update Product, Show Post) by manipulating the model -and directing data to the view. - -In Rails, the model is handled by what's called an object-relational mapping -layer entitled Active Record. This layer allows you to present the data from -database rows as objects and embellish these data objects with business logic -methods. You can read more about Active Record in -link:files/vendor/rails/activerecord/README.html. - -The controller and view are handled by the Action Pack, which handles both -layers by its two parts: Action View and Action Controller. These two layers -are bundled in a single package due to their heavy interdependence. This is -unlike the relationship between the Active Record and Action Pack that is much -more separate. Each of these packages can be used independently outside of -Rails. You can read more about Action Pack in -link:files/vendor/rails/actionpack/README.html. - - -== Getting Started - -1. At the command prompt, create a new Rails application: - rails new myapp (where myapp is the application name) - -2. Change directory to myapp and start the web server: - cd myapp; rails server (run with --help for options) - -3. Go to http://localhost:3000/ and you'll see: - "Welcome aboard: You're riding Ruby on Rails!" - -4. Follow the guidelines to start developing your application. You can find -the following resources handy: - -* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html -* Ruby on Rails Tutorial Book: http://www.railstutorial.org/ - - -== Debugging Rails - -Sometimes your application goes wrong. Fortunately there are a lot of tools that -will help you debug it and get it back on the rails. - -First area to check is the application log files. Have "tail -f" commands -running on the server.log and development.log. Rails will automatically display -debugging and runtime information to these files. Debugging info will also be -shown in the browser on requests from 127.0.0.1. - -You can also log your own messages directly into the log file from your code -using the Ruby logger class from inside your controllers. Example: - - class WeblogController < ActionController::Base - def destroy - @weblog = Weblog.find(params[:id]) - @weblog.destroy - logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!") - end - end - -The result will be a message in your log file along the lines of: - - Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1! - -More information on how to use the logger is at http://www.ruby-doc.org/core/ - -Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are -several books available online as well: - -* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe) -* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) - -These two books will bring you up to speed on the Ruby language and also on -programming in general. - - -== Debugger - -Debugger support is available through the debugger command when you start your -Mongrel or WEBrick server with --debugger. This means that you can break out of -execution at any point in the code, investigate and change the model, and then, -resume execution! You need to install ruby-debug to run the server in debugging -mode. With gems, use sudo gem install ruby-debug. Example: - - class WeblogController < ActionController::Base - def index - @posts = Post.all - debugger - end - end - -So the controller will accept the action, run the first line, then present you -with a IRB prompt in the server window. Here you can do things like: - - >> @posts.inspect - => "[#nil, "body"=>nil, "id"=>"1"}>, - #"Rails", "body"=>"Only ten..", "id"=>"2"}>]" - >> @posts.first.title = "hello from a debugger" - => "hello from a debugger" - -...and even better, you can examine how your runtime objects actually work: - - >> f = @posts.first - => #nil, "body"=>nil, "id"=>"1"}> - >> f. - Display all 152 possibilities? (y or n) - -Finally, when you're ready to resume execution, you can enter "cont". - - -== Console - -The console is a Ruby shell, which allows you to interact with your -application's domain model. Here you'll have all parts of the application -configured, just like it is when the application is running. You can inspect -domain models, change values, and save to the database. Starting the script -without arguments will launch it in the development environment. - -To start the console, run rails console from the application -directory. - -Options: - -* Passing the -s, --sandbox argument will rollback any modifications - made to the database. -* Passing an environment name as an argument will load the corresponding - environment. Example: rails console production. - -To reload your controllers and models after launching the console run -reload! - -More information about irb can be found at: -link:http://www.rubycentral.org/pickaxe/irb.html - - -== dbconsole - -You can go to the command line of your database directly through rails -dbconsole. You would be connected to the database with the credentials -defined in database.yml. Starting the script without arguments will connect you -to the development database. Passing an argument will connect you to a different -database, like rails dbconsole production. Currently works for MySQL, -PostgreSQL and SQLite 3. - -== Description of Contents - -The default directory structure of a generated Ruby on Rails application: - - |-- app - | |-- assets - | |-- images - | |-- javascripts - | `-- stylesheets - | |-- controllers - | |-- helpers - | |-- mailers - | |-- models - | `-- views - | `-- layouts - |-- config - | |-- environments - | |-- initializers - | `-- locales - |-- db - |-- doc - |-- lib - | `-- tasks - |-- log - |-- public - |-- script - |-- test - | |-- fixtures - | |-- functional - | |-- integration - | |-- performance - | `-- unit - |-- tmp - | |-- cache - | |-- pids - | |-- sessions - | `-- sockets - `-- vendor - |-- assets - `-- stylesheets - `-- plugins - -app - Holds all the code that's specific to this particular application. - -app/assets - Contains subdirectories for images, stylesheets, and JavaScript files. - -app/controllers - Holds controllers that should be named like weblogs_controller.rb for - automated URL mapping. All controllers should descend from - ApplicationController which itself descends from ActionController::Base. - -app/models - Holds models that should be named like post.rb. Models descend from - ActiveRecord::Base by default. - -app/views - Holds the template files for the view that should be named like - weblogs/index.html.erb for the WeblogsController#index action. All views use - eRuby syntax by default. - -app/views/layouts - Holds the template files for layouts to be used with views. This models the - common header/footer method of wrapping views. In your views, define a layout - using the layout :default and create a file named default.html.erb. - Inside default.html.erb, call <% yield %> to render the view using this - layout. - -app/helpers - Holds view helpers that should be named like weblogs_helper.rb. These are - generated for you automatically when using generators for controllers. - Helpers can be used to wrap functionality for your views into methods. - -config - Configuration files for the Rails environment, the routing map, the database, - and other dependencies. - -db - Contains the database schema in schema.rb. db/migrate contains all the - sequence of Migrations for your schema. - -doc - This directory is where your application documentation will be stored when - generated using rake doc:app - -lib - Application specific libraries. Basically, any kind of custom code that - doesn't belong under controllers, models, or helpers. This directory is in - the load path. - -public - The directory available for the web server. Also contains the dispatchers and the - default HTML files. This should be set as the DOCUMENT_ROOT of your web - server. - -script - Helper scripts for automation and generation. - -test - Unit and functional tests along with fixtures. When using the rails generate - command, template test files will be generated for you and placed in this - directory. - -vendor - External libraries that the application depends on. Also includes the plugins - subdirectory. If the app has frozen rails, those gems also go here, under - vendor/rails/. This directory is in the load path. diff --git a/app/assets/images/fallback/y2012_main_img.png b/app/assets/images/fallback/y2012_main_img.png new file mode 100755 index 0000000..de89860 Binary files /dev/null and b/app/assets/images/fallback/y2012_main_img.png differ diff --git a/app/assets/images/y2012_main_img.png b/app/assets/images/y2012_main_img.png new file mode 100755 index 0000000..de89860 Binary files /dev/null and b/app/assets/images/y2012_main_img.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 3e80fe1..65b8731 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,7 @@ // //= require jquery //= require jquery_ujs +//= require jquery.countdown //= require twitter/bootstrap //= require_tree . diff --git a/app/assets/javascripts/bootstrap.js.coffee b/app/assets/javascripts/bootstrap.js.coffee index c9404a8..9440679 100644 --- a/app/assets/javascripts/bootstrap.js.coffee +++ b/app/assets/javascripts/bootstrap.js.coffee @@ -1,4 +1,3 @@ jQuery -> - $("a[rel=popover]").popover() - $(".tooltip").tooltip() - $("a[rel=tooltip]").tooltip() \ No newline at end of file + $("a[rel~=popover], .has-popover").popover() + $("a[rel~=tooltip], .has-tooltip").tooltip() diff --git a/app/assets/javascripts/y2012.js b/app/assets/javascripts/y2012.js new file mode 100644 index 0000000..3e80fe1 --- /dev/null +++ b/app/assets/javascripts/y2012.js @@ -0,0 +1,38 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// +// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD +// GO AFTER THE REQUIRES BELOW. +// +//= require jquery +//= require jquery_ujs +//= require twitter/bootstrap +//= require_tree . + +$(document).ready(function() { + $('a.link-not-implemented').on('click', function() { + event.preventDefault(); + alert('준비중입니다'); + }); + + $('.navbar.navbar-fixed-top .logo').hover(function(){ + $('.navbar.navbar-fixed-top .logo').stop().animate({"top":"0"},600); + },function(){ + $('.navbar.navbar-fixed-top .logo').stop().animate({"top":"-135"},600); + }); + + var $container = $('.masonry_container'); + $container.imagesLoaded(function(){ + $container.masonry({ + itemSelector : '.masonry_item:visible' + }); + }); + +}); + diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 7d01d57..4ac49ce 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -10,6 +10,8 @@ * *= require_self *= require_tree . + *= require bootstrap_and_overrides + *= require jquery.countdown */ .footer { @@ -31,4 +33,4 @@ div.selected div.infobox { section#promises div.masonry_item:not(.selected), section#awards div.masonry_item:not(.selected) { display: none; -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 7616b79..0cd89fc 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -1,23 +1,19 @@ @import "twitter/bootstrap/bootstrap"; -@import "./responsive"; - -body { padding-top: 40px; } +@import "twitter/bootstrap/responsive"; // Set the correct sprite paths -@iconSpritePath: asset-path("twitter/bootstrap/glyphicons-halflings"); -@iconWhiteSpritePath: asset-path("twitter/bootstrap/glyphicons-halflings-white"); +@iconSpritePath: image-url("twitter/bootstrap/glyphicons-halflings.png"); +@iconWhiteSpritePath: image-url("twitter/bootstrap/glyphicons-halflings-white.png"); // Set the Font Awesome (Font Awesome is default. You can disable by commenting below lines) -// Note: If you use asset_path() here, your compiled bootstrap_and_overrides.css will not -// have the proper paths. So for now we use the absolute path. -@fontAwesomeEotPath: asset-path("fontawesome-webfont.eot"); -@fontAwesomeEotPath_iefix: asset-path("fontawesome-webfont.eot#iefix"); -@fontAwesomeWoffPath: asset-path("fontawesome-webfont.woff"); -@fontAwesomeTtfPath: asset-path("fontawesome-webfont.ttf"); -@fontAwesomeSvgPath: asset-path("fontawesome-webfont.svg"); +@fontAwesomeEotPath: asset-url("fontawesome-webfont.eot"); +@fontAwesomeEotPath_iefix: asset-url("fontawesome-webfont.eot?#iefix"); +@fontAwesomeWoffPath: asset-url("fontawesome-webfont.woff"); +@fontAwesomeTtfPath: asset-url("fontawesome-webfont.ttf"); +@fontAwesomeSvgPath: asset-url("fontawesome-webfont.svg#fontawesomeregular"); // Font Awesome -@import "fontawesome"; +@import "fontawesome/font-awesome"; // Glyphicons //@import "twitter/bootstrap/sprites.less"; @@ -31,4 +27,4 @@ body { padding-top: 40px; } // See http://twitter.github.com/bootstrap/customize.html#variables for their names and documentation // // Example: -// @linkColor: #ff0000; \ No newline at end of file +// @linkColor: #ff0000; diff --git a/app/assets/stylesheets/y2012.css.scss b/app/assets/stylesheets/y2012.css.scss new file mode 100644 index 0000000..cfce16e --- /dev/null +++ b/app/assets/stylesheets/y2012.css.scss @@ -0,0 +1,35 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the top of the + * compiled file, but it's generally better to create a new file per style scope. + * + *= require_self + *= require_tree . + *= require bootstrap_and_overrides + */ + +.footer { + margin-top: 2em; + padding: 2em; + a { + color: #333; + } +} + +div.infobox { + border: 1px solid #DDDDDD; border-radius: 5px; margin-bottom: 1em; padding: 1em; background: #F5F5F5; +} +div.selected div.infobox { + border-color: #CCC6B4; + background: #FFF5D8; +} + +section#promises div.masonry_item:not(.selected), +section#awards div.masonry_item:not(.selected) { + display: none; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e8065d9..5c06e02 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,4 @@ class ApplicationController < ActionController::Base + include ApplicationHelper protect_from_forgery end diff --git a/app/controllers/awards_controller.rb b/app/controllers/awards_controller.rb index 1bdf878..9240b2f 100644 --- a/app/controllers/awards_controller.rb +++ b/app/controllers/awards_controller.rb @@ -1,14 +1,14 @@ class AwardsController < ApplicationController def index - @awards = Award.all + @awards = current_election.awards #Award.all end def new - @award = current_user.awards.build + @award = Award.new(user: current_user, election: current_election) end def create - @award = current_user.awards.build(params[:award]) + @award = Award.new(award_params.merge({user: current_user, election: current_election})) if @award.save message = I18n.t('award.share', username: current_user.name, title: @award.title, content: @award.content, prize: @award.prize) if current_user.omniauth_provider == :twitter @@ -36,13 +36,19 @@ def destroy def edit @award = Award.find(params[:id]) + @promises = current_election.promises end def update award = Award.find(params[:id]) if current_user.admin? || award.user == current_user - award.update_attributes(params[:award]) + award.update_attributes(award_params) end redirect_to award end -end \ No newline at end of file + +private + def award_params + params.require(:award).permit(:title, :content, :prize, :url, :address) + end +end diff --git a/app/controllers/campaigns_controller.rb b/app/controllers/campaigns_controller.rb index 96f44bb..b351f72 100644 --- a/app/controllers/campaigns_controller.rb +++ b/app/controllers/campaigns_controller.rb @@ -8,7 +8,7 @@ def new end def create - @campaign = current_user.campaigns.build(params[:campaign]) + @campaign = current_user.campaigns.build(campaign_params) if @campaign.save redirect_to campaigns_path, notice: I18n.t('campaign.created') else @@ -22,7 +22,7 @@ def edit def update @campaign = Campaign.find(params[:id]) - if @campaign.update_attributes(params[:campaign]) + if @campaign.update_attributes(campaign) redirect_to campaigns_path, notice: I18n.t('campaign.updated') else render action: 'edit' @@ -32,4 +32,9 @@ def update def destroy end -end \ No newline at end of file + +private + def campaign_params + params.require(:campaign).permit() + end +end diff --git a/app/controllers/candidates_controller.rb b/app/controllers/candidates_controller.rb index ca053db..e627aae 100644 --- a/app/controllers/candidates_controller.rb +++ b/app/controllers/candidates_controller.rb @@ -40,7 +40,7 @@ def edit # POST /candidates # POST /candidates.json def create - @candidate = Candidate.new(params[:candidate]) + @candidate = Candidate.new(candidate_params) respond_to do |format| if @candidate.save @@ -59,7 +59,7 @@ def update @candidate = Candidate.find(params[:id]) respond_to do |format| - if @candidate.update_attributes(params[:candidate]) + if @candidate.update_attributes(candidate_params) format.html { redirect_to candidates_url, notice: 'Candidate was successfully updated.' } format.json { head :no_content } else @@ -80,4 +80,9 @@ def destroy format.json { head :no_content } end end + +private + def candidate_params + params.require(:candidate).permit(:name, :party, :number, :election_id) + end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index d1e6cae..b764ec0 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,7 +1,7 @@ class CommentsController < ApplicationController def create @commentable = find_commentable - @comment = @commentable.comments.build(params[:comment]) + @comment = @commentable.comments.build(comment_params) @comment.user = current_user respond_to do |format| @@ -26,7 +26,7 @@ def destroy end end - private +private def find_commentable params.each do |name, value| if name =~ /(.+)_id$/ @@ -34,4 +34,8 @@ def find_commentable end end end -end \ No newline at end of file + + def comment_params + params.require(:comment).permit() + end +end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 897d84d..801cfd4 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -8,7 +8,7 @@ def new end def create - @event = current_user.events.build(params[:event]) + @event = current_user.events.build(event_params) if @event.save redirect_to events_path, notice: I18n.t('event.created') else @@ -26,7 +26,7 @@ def edit def update @event = current_user.events.find(params[:id]) - if @event.update_attributes(params[:event]) + if @event.update_attributes(event_params) redirect_to events_path, notice: I18n.t('event.updated') else render action: 'edit' @@ -35,4 +35,9 @@ def update def destroy end -end \ No newline at end of file + +private + def event_params + params.require(:event).permit(:title, :content, :address, :coordinates, :image, :limit) + end +end diff --git a/app/controllers/giveups_controller.rb b/app/controllers/giveups_controller.rb index f567c34..4acbfc2 100644 --- a/app/controllers/giveups_controller.rb +++ b/app/controllers/giveups_controller.rb @@ -5,7 +5,7 @@ def index end def create - @giveup = current_user.build_giveup(params[:giveup]) + @giveup = current_user.build_giveup(giveup_params) if @giveup.save redirect_to giveups_url, notice: I18n.t('giveup.created') else @@ -21,4 +21,9 @@ def destroy redirect_to giveups_url end end -end \ No newline at end of file + +private + def giveup_params + params.require(:giveup).permit() + end +end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index f2f1297..9d3c26f 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,5 +1,9 @@ class PagesController < ApplicationController def home + @promises_count = current_election.promises.count + @awards_count = current_election.awards.count + @votes_count = current_election.votes.count + @events_count = current_election.events.count end def info @@ -7,4 +11,10 @@ def info def discuss end -end \ No newline at end of file + + def count + @diff = (Time.new(2017, 5, 9, 20, 0, 0, "+09:00") - Time.now).to_i + render layout: false + # Time.at(time_diff.round.abs).utc.strftime "%H:%M:%S" + end +end diff --git a/app/controllers/promises_controller.rb b/app/controllers/promises_controller.rb index d8b0f17..9d8ad28 100644 --- a/app/controllers/promises_controller.rb +++ b/app/controllers/promises_controller.rb @@ -1,26 +1,27 @@ class PromisesController < ApplicationController + before_action :current_candidates + before_action :current_promises, only: [:index] + def index - @promises = Promise.all end def new - @promise = current_user.build_promise + @promise = Promise.new(user: current_user, election: current_election) end def create - @promise = current_user.build_promise(params[:promise]) - redirect_to promises_url - # if @promise.save - # message = I18n.t('promise.share', username: current_user.name, reason: @promise.reason, seq: @promise.seq) - # if current_user.omniauth_provider == :twitter - # current_user.twitter.update([promises_url, message, I18n.t('g.hashtag')].join(' ')) - # else - # current_user.facebook.put_wall_post(message, {name: I18n.t('g.title'), link: promises_url}) - # end - # redirect_to promises_path, notice: I18n.t('promise.created') - # else - # render action: 'new' - # end + @promise = Promise.new(promise_params.merge({user: current_user, election: current_election, })) + if @promise.save + message = I18n.t('promise.share', username: current_user.name, reason: @promise.reason, seq: @promise.seq) + if current_user.omniauth_provider == :twitter + current_user.twitter.update([promises_url, message, I18n.t('g.hashtag')].join(' ')) + else + current_user.facebook.put_wall_post(message, {name: I18n.t('g.title'), link: promises_url}) + end + redirect_to promises_path, notice: I18n.t('promise.created') + else + render action: 'new' + end end def show @@ -28,13 +29,13 @@ def show end def edit - @promise = current_user.promise + @promise = Promise.where(user: current_user, election: current_election).first end def update - @promise = current_user.promise + @promise = Promise.where(user: current_user, election: current_election).first redirect_to promises_url if @promise.user != current_user - if @promise.update_attributes(params[:promise]) + if @promise.update_attributes(promise_params) redirect_to promises_url, notice: I18n.t('promise.updated') else redirect_to promises_url @@ -45,4 +46,17 @@ def like @promise = Promise.find(params[:id]) @promise.inc(:likes, 1) end -end \ No newline at end of file + +private + def promise_params + params.require(:promise).permit(:reason, :area, :sex, :age, :candidate_id, :show_candidate) + end + + def current_candidates + @candidates = current_election.candidates + end + + def current_promises + @promises = current_election.promises + end +end diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb index a6fbc48..2c5c774 100644 --- a/app/controllers/votes_controller.rb +++ b/app/controllers/votes_controller.rb @@ -1,7 +1,7 @@ class VotesController < ApplicationController def index - @votes = Vote.all - @events = Event.all + @votes = current_election.votes + @events = current_election.events end def new @@ -14,7 +14,7 @@ def create return nil end - @vote = current_user.votes.build(params[:vote]) + @vote = Vote.new(vote_params.merge({user: current_user, election: current_election})) if @vote.save message = I18n.t('vote.share', username: current_user.name, title: @vote.title, content: @vote.content, seq: @vote.seq) if current_user.omniauth_provider == :twitter @@ -34,7 +34,7 @@ def edit def update @vote = current_user.votes.find(params[:id]) - if @vote.update_attributes(params[:vote]) + if @vote.update_attributes(vote_params) redirect_to votes_url, notice: I18n.t('vote.updated') else render action: 'edit' @@ -44,6 +44,7 @@ def update def show @vote = Vote.find(params[:id]) @vote.comments.build + @promises = @vote.user.promises end def like @@ -51,4 +52,9 @@ def like @vote.inc(:likes, 1) @vote.event.inc(:likes, 1) unless @vote.event.blank? end -end \ No newline at end of file + +private + def vote_params + params.require(:vote).permit(:image, :title, :content, :event) + end +end diff --git a/app/controllers/y2012/awards_controller.rb b/app/controllers/y2012/awards_controller.rb new file mode 100644 index 0000000..c574af3 --- /dev/null +++ b/app/controllers/y2012/awards_controller.rb @@ -0,0 +1,55 @@ +class Y2012::AwardsController < Y2012::Y2012Controller + def index + @awards = Award.where(election: current_election) + end + + def new + @award = Award.new(user: current_user, election: current_election) + end + + def create + @award = Award.new(award_params.merge({user: current_user, election: current_election})) + if @award.save + message = I18n.t('award.share', username: current_user.name, title: @award.title, content: @award.content, prize: @award.prize) + if current_user.omniauth_provider == :twitter + current_user.twitter.update([awards_url, message, I18n.t('g.hashtag')].join(' ')) + else + current_user.facebook.put_wall_post(message, {name: I18n.t('g.title'), link: awards_url}) + end + redirect_to awards_url, notice: I18n.t('award.created') + else + render action: 'new' + end + end + + def show + @award = Award.find(params[:id]) + @award.comments.build + @promises = Promise.where(user: @award.user, election: current_election) + end + + def destroy + @award = Award.find(params[:id]) + if current_user.admin? && @award.destroy + redirect_to awards_url + end + end + + def edit + @award = Award.find(params[:id]) + @promises = current_election.promises + end + + def update + award = Award.find(params[:id]) + if current_user.admin? || award.user == current_user + award.update_attributes(award_params) + end + redirect_to award + end + +private + def award_params + params.require(:award).permit(:title, :content, :prize, :url, :address) + end +end diff --git a/app/controllers/y2012/events_controller.rb b/app/controllers/y2012/events_controller.rb new file mode 100644 index 0000000..8a9846c --- /dev/null +++ b/app/controllers/y2012/events_controller.rb @@ -0,0 +1,43 @@ +class Y2012::EventsController < Y2012::Y2012Controller + def index + @events = Event.all + end + + def new + @event = current_user.events.build + end + + def create + @event = current_user.events.build(event_params) + if @event.save + redirect_to events_path, notice: I18n.t('event.created') + else + render action: 'new' + end + end + + def show + @event = Event.find(params[:id]) + end + + def edit + @event = current_user.events.find(params[:id]) + end + + def update + @event = current_user.events.find(params[:id]) + if @event.update_attributes(event_params) + redirect_to events_path, notice: I18n.t('event.updated') + else + render action: 'edit' + end + end + + def destroy + end + +private + def event_params + params.require(:event).permit() + end +end diff --git a/app/controllers/y2012/pages_controller.rb b/app/controllers/y2012/pages_controller.rb new file mode 100644 index 0000000..ef03a34 --- /dev/null +++ b/app/controllers/y2012/pages_controller.rb @@ -0,0 +1,15 @@ +class Y2012::PagesController < Y2012::Y2012Controller + def home + past_election = Election.where(title: '제18대 대통령선거').first + @promises_count = past_election.promises.count + @awards_count = past_election.awards.count + @votes_count = past_election.votes.count + @events_count = past_election.events.count + end + + def info + end + + def discuss + end +end diff --git a/app/controllers/y2012/promises_controller.rb b/app/controllers/y2012/promises_controller.rb new file mode 100644 index 0000000..ef4e679 --- /dev/null +++ b/app/controllers/y2012/promises_controller.rb @@ -0,0 +1,63 @@ +class Y2012::PromisesController < Y2012::Y2012Controller + before_action :current_candidates + before_action :current_promises, only: [:index] + + def index + end + + def new + @promise = current_user.build_promise + end + + def create + @promise = current_user.build_promise(promise_params) + redirect_to promises_url + # if @promise.save + # message = I18n.t('promise.share', username: current_user.name, reason: @promise.reason, seq: @promise.seq) + # if current_user.omniauth_provider == :twitter + # current_user.twitter.update([promises_url, message, I18n.t('g.hashtag')].join(' ')) + # else + # current_user.facebook.put_wall_post(message, {name: I18n.t('g.title'), link: promises_url}) + # end + # redirect_to promises_path, notice: I18n.t('promise.created') + # else + # render action: 'new' + # end + end + + def show + @promise = Promise.find(params[:id]) + end + + def edit + @promise = current_user.promise + end + + def update + @promise = current_user.promise + redirect_to promises_url if @promise.user != current_user + if @promise.update_attributes(params[:promise]) + redirect_to promises_url, notice: I18n.t('promise.updated') + else + redirect_to promises_url + end + end + + def like + @promise = Promise.find(params[:id]) + @promise.inc(:likes, 1) + end + +private + def promise_params + params.require(:promise).permit(:reason, :area, :sex, :age, :candidate_id, :show_candidate) + end + + def current_candidates + @candidates = current_election.candidates + end + + def current_promises + @promises = current_election.promises + end +end diff --git a/app/controllers/y2012/votes_controller.rb b/app/controllers/y2012/votes_controller.rb new file mode 100644 index 0000000..d2d0f9a --- /dev/null +++ b/app/controllers/y2012/votes_controller.rb @@ -0,0 +1,60 @@ +class Y2012::VotesController < Y2012::Y2012Controller + def index + @votes = Vote.all + @events = Event.all + end + + def new + @vote = current_user.votes.build() + end + + def create + unless user_signed_in? && current_user.votes.empty? + redirect_to votes_url + return nil + end + + @vote = current_user.votes.build(vote_params) + if @vote.save + message = I18n.t('vote.share', username: current_user.name, title: @vote.title, content: @vote.content, seq: @vote.seq) + if current_user.omniauth_provider == :twitter + current_user.twitter.update([vote_url(@vote), message, I18n.t('g.hashtag')].join(' ')) + else + current_user.facebook.put_wall_post(message, {name: I18n.t('g.title'), link: vote_url(@vote)}) + end + redirect_to votes_url, notice: I18n.t('vote.created') + else + render action: 'new' + end + end + + def edit + @vote = current_user.votes.find(params[:id]) + end + + def update + @vote = current_user.votes.find(params[:id]) + if @vote.update_attributes(vote_params) + redirect_to votes_url, notice: I18n.t('vote.updated') + else + render action: 'edit' + end + end + + def show + @vote = Vote.find(params[:id]) + @vote.comments.build + @promises = @vote.user.promises + end + + def like + @vote = Vote.find(params[:id]) + @vote.inc(:likes, 1) + @vote.event.inc(:likes, 1) unless @vote.event.blank? + end + +private + def vote_params + params.require(:vote).permit(:image, :title, :content, :event) + end +end diff --git a/app/controllers/y2012/y2012_controller.rb b/app/controllers/y2012/y2012_controller.rb new file mode 100644 index 0000000..9bfe91d --- /dev/null +++ b/app/controllers/y2012/y2012_controller.rb @@ -0,0 +1,8 @@ +class Y2012::Y2012Controller < ActionController::Base + layout 'y2012' + protect_from_forgery + + def current_election + Election.where(title: '제18대 대통령선거').first + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..087fadb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def current_election + Election.where(title: '제19대 대통령선거').first + end end diff --git a/app/helpers/y2012_helper.rb b/app/helpers/y2012_helper.rb new file mode 100644 index 0000000..7f6e29a --- /dev/null +++ b/app/helpers/y2012_helper.rb @@ -0,0 +1,2 @@ +module Y2012Helper +end diff --git a/app/models/award.rb b/app/models/award.rb index 7d606e7..0928a98 100644 --- a/app/models/award.rb +++ b/app/models/award.rb @@ -6,6 +6,7 @@ class Award belongs_to :user has_many :comments, as: :commentable has_and_belongs_to_many :promises + belongs_to :election #fields field :title @@ -18,5 +19,6 @@ class Award validates_presence_of :title, :content, :prize # scopes - default_scope desc(:_id) -end \ No newline at end of file + default_scope -> { order(_id: :desc) } + +end diff --git a/app/models/campaign.rb b/app/models/campaign.rb index d8f6165..aab6b58 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -16,7 +16,7 @@ class Campaign validates_presence_of :url, :title, :description # scope - default_scope desc(:_id) + default_scope -> { order(_id: :desc) } # callbacks -end \ No newline at end of file +end diff --git a/app/models/candidate.rb b/app/models/candidate.rb index 7504f83..5ce3e53 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -1,8 +1,14 @@ class Candidate include Mongoid::Document include Mongoid::Timestamps + + belongs_to :election has_many :promises + field :name field :party field :number -end \ No newline at end of file + + validates_presence_of :name, :election_id + +end diff --git a/app/models/comment.rb b/app/models/comment.rb index 44f4331..50fd2d8 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -13,5 +13,5 @@ class Comment validates_presence_of :content # scope - default_scope asc(:_id) -end \ No newline at end of file + default_scope -> { order(_id: :asc) } +end diff --git a/app/models/election.rb b/app/models/election.rb new file mode 100644 index 0000000..a3457fd --- /dev/null +++ b/app/models/election.rb @@ -0,0 +1,18 @@ +class Election + include Mongoid::Document + include Mongoid::Timestamps + + has_many :candidates + has_many :promises + has_many :sequences + has_many :votes + has_many :awards + has_many :events + + field :title + field :content + + validates_presence_of :title, :content + + default_scope -> { order(_id: :desc) } +end diff --git a/app/models/event.rb b/app/models/event.rb index 3fc76f2..c272ac8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -6,6 +6,7 @@ class Event # association belongs_to :user has_many :votes + belongs_to :election # fields field :title @@ -23,7 +24,8 @@ class Event validates_presence_of :title, :content # scope - default_scope desc(:_id) + default_scope -> { order(_id: :desc) } + # geocode geocoded_by :address @@ -32,4 +34,4 @@ class Event after_validation :geocode # scope -end \ No newline at end of file +end diff --git a/app/models/giveup.rb b/app/models/giveup.rb index 4daf4fc..24e0f7d 100644 --- a/app/models/giveup.rb +++ b/app/models/giveup.rb @@ -15,5 +15,5 @@ class Giveup validates_presence_of :reason, :area, :sex, :age # scopes - default_scope desc(:_id) -end \ No newline at end of file + default_scope -> { order(_id: :desc) } +end diff --git a/app/models/promise.rb b/app/models/promise.rb index ef65bd8..aad0fae 100644 --- a/app/models/promise.rb +++ b/app/models/promise.rb @@ -2,33 +2,30 @@ class Promise include Mongoid::Document include Mongoid::Timestamps - # association belongs_to :user belongs_to :candidate has_and_belongs_to_many :awards + belongs_to :election - # fields field :show_candidate, type: Boolean, default: true - field :seq, type: Integer + field :seq, type: Integer, default: 1 field :reason field :area field :sex field :age field :likes, type: Integer, default: 0 - # validation validates_presence_of :reason, :area, :sex, :age validates_uniqueness_of :user_id - # scope - default_scope desc(:_id) + default_scope -> { order(_id: :desc) } - # callbacks before_create :assign_id private def assign_id - self.seq = Sequence.generate_id(:promise) + Sequence.generate_id(self.election, :promise) + self.seq = Sequence.get_last_id(self.election, :promise) end -end \ No newline at end of file +end diff --git a/app/models/sequence.rb b/app/models/sequence.rb index d735d17..f85d2ff 100644 --- a/app/models/sequence.rb +++ b/app/models/sequence.rb @@ -1,15 +1,18 @@ class Sequence include Mongoid::Document + + belongs_to :election + field :object field :last_id, type: Integer - def self.generate_id(object) - @seq=where(:object => object).first || create(:object => object) - @seq.inc(:last_id,1) + def self.generate_id(election, object) + @seq=where(election: election, object: object).first || create(election: election, object: object) + @seq.inc(last_id: 1) end - def self.get_last_id(object) - @seq=where(:object => object).first - (@seq.blank?) ? 0 : @seq.last_id + def self.get_last_id(election, object) + @seq=where(election: election, object: object).first + (@seq.blank?) ? 1 : @seq.last_id end -end \ No newline at end of file +end diff --git a/app/models/user.rb b/app/models/user.rb index c4ad216..018b156 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,7 +3,7 @@ class User include Mongoid::Timestamps # association - has_one :promise + has_many :promises has_one :giveup has_many :votes has_many :awards @@ -59,6 +59,11 @@ def email_required? field :omniauth_uid field :omniauth_credentials field :omniauth_url + field :omniauth_image + field :omniauth + + field :name + field :password # methods def admin? @@ -74,10 +79,12 @@ def profile_image end def twitter - @twitter ||= Twitter::Client.new( - oauth_token: omniauth_credentials['token'], - oauth_token_secret: omniauth_credentials['secret'] - ) + @twitter ||= Twitter::REST::Client.new do |config| + config.consumer_key = Rails.configuration.twitter['client_id'] + config.consumer_secret = Rails.configuration.twitter['client_secret'] + config.access_token = omniauth_credentials['token'] + config.access_token_secret = omniauth_credentials['secret'] + end end def facebook @@ -87,4 +94,4 @@ def facebook logger.info e.to_s nil # or consider a custom null object end -end \ No newline at end of file +end diff --git a/app/models/vote.rb b/app/models/vote.rb index fb65c4e..55fb9bb 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -6,6 +6,7 @@ class Vote belongs_to :user belongs_to :event has_many :comments, as: :commentable + belongs_to :election # fields field :seq, type: Integer @@ -19,7 +20,7 @@ class Vote validates_presence_of :title, :content # scope - default_scope desc(:_id) + default_scope -> { order(_id: :desc) } # callbacks before_create :assign_id @@ -29,7 +30,8 @@ class Vote protected def assign_id - self.seq = Sequence.generate_id(:vote) + Sequence.generate_id(self.election, :vote) + self.seq = Sequence.get_last_id(self.election, :vote) end def set_location @@ -46,6 +48,7 @@ def extract_geocoordinates lng_ref = image.get_exif('GPSLongitudeRef') rescue nil return unless img_lat && img_lng && lat_ref && lng_ref + return if img_lat.blank? && img_lng.blank? && lat_ref.blank? && lng_ref.blank? latitude = to_frac(img_lat[0]) + (to_frac(img_lat[1])/60) + (to_frac(img_lat[2])/3600) longitude = to_frac(img_lng[0]) + (to_frac(img_lng[1])/60) + (to_frac(img_lng[2])/3600) @@ -67,4 +70,4 @@ def to_frac(strng) denominator ||= 1 numerator/denominator end -end \ No newline at end of file +end diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index ff5e1eb..2514a20 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -2,14 +2,16 @@ class ImageUploader < CarrierWave::Uploader::Base - include CarrierWave::RMagick + # include CarrierWave::RMagick + include CarrierWave::MiniMagick # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility: - include Sprockets::Helpers::RailsHelper - include Sprockets::Helpers::IsolatedHelper + # include Sprockets::Helpers::RailsHelper # 4.0 + # include Sprockets::Helpers::IsolatedHelper # 4.0 # Choose what kind of storage to use for this uploader: storage :fog + # storage :file # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: @@ -55,4 +57,4 @@ def get_exif( name ) return img["EXIF:" + name] end end -end \ No newline at end of file +end diff --git a/app/views/application/_encourage_box.html.erb b/app/views/application/_encourage_box.html.erb index e69de29..09b4833 100644 --- a/app/views/application/_encourage_box.html.erb +++ b/app/views/application/_encourage_box.html.erb @@ -0,0 +1,7 @@ +<% unless user_signed_in? %> +
+

투표 대잔치 <%= current_election.promises.count + 1 %>번째의 주인공이 되어 주세요!

+ <%= link_to raw(" 페이스북으로 시작하기"), user_facebook_omniauth_authorize_path, class: 'btn btn-primary btn-large' %> + <%= link_to raw(" 트위터로 시작하기"), user_twitter_omniauth_authorize_path, class: 'btn btn-primary btn-large' %> +
+<% end %> diff --git a/app/views/awards/edit.html.erb b/app/views/awards/edit.html.erb index 693f9bc..46cd5ed 100644 --- a/app/views/awards/edit.html.erb +++ b/app/views/awards/edit.html.erb @@ -9,7 +9,7 @@ <%= simple_form_for @award do |f| %> <%= f.error_notification %>
- <% promises_array = Promise.all.collect{|p| ["#{p.seq} - #{p.user.name}", p.id] } %> + <% promises_array = @promises.collect{ |x| ["#{x.seq} - #{x.user.name}", x.id] } %> <%= f.association :promises, as: :check_boxes, label: '수상자', collection: promises_array, item_wrapper_class: 'inline' %>
@@ -17,4 +17,4 @@
<% end %> - \ No newline at end of file + diff --git a/app/views/awards/index.html.erb b/app/views/awards/index.html.erb index 56ec35e..c727f2c 100644 --- a/app/views/awards/index.html.erb +++ b/app/views/awards/index.html.erb @@ -2,25 +2,24 @@
- <% if user_signed_in? && current_user.awards.present? %> -
- <%- award = current_user.awards.first -%> - '<%= content_tag :b, award.title %>' 어워드의 당첨자를 정해주세요! - <%= link_to edit_award_path(award), class: 'btn btn-info' do %> - 당첨자 지정하기 - <% end %> + <%= render 'encourage_box' %> + + <% if user_signed_in? %> +
+

누구든지 투표를 약속한 사람들에게 어워드를 부여할 수 있습니다. + 지금 바로 <%= content_tag :b, current_user.name %>님만의 어워드를 만들어 보세요!

+ <%= link_to "#{current_election.title} 투표대잔치 '#{current_user.name} 어워드' 만들기", new_award_path, class: 'btn btn-primary btn-large' %>
<% end %> - <%= render 'encourage_box' %>
@@ -43,4 +42,4 @@ $('.masonry_item.selected').show(); $('.masonry_container').masonry('reload'); } - \ No newline at end of file + diff --git a/app/views/awards/show.html.erb b/app/views/awards/show.html.erb index 2c66ce5..300dbf1 100644 --- a/app/views/awards/show.html.erb +++ b/app/views/awards/show.html.erb @@ -16,10 +16,10 @@

<%= simple_format @award.content %>

- <% if @award.promises.present? %> + <% if @award.promises.where(election: current_election).present? %>
- <%= render @award.promises %> + <%= render @award.promises.where(election: current_election) %>

<% end %> @@ -54,13 +54,13 @@

<%= @award.address %>

<% end %> - <% unless @award.user.promise.blank? %> + <% unless @award.user.promises.blank? %>

만든 사람이 한 투표 약속

-

<%= @award.user.promise.reason %>

+

<%= @award.user.promises.where(election: current_election).first.reason %>

<% end %>
- \ No newline at end of file + diff --git a/app/views/candidates/_form.html.erb b/app/views/candidates/_form.html.erb index 60144bb..4bbadca 100644 --- a/app/views/candidates/_form.html.erb +++ b/app/views/candidates/_form.html.erb @@ -1,5 +1,5 @@ <%= simple_form_for @candidate, :html => { :class => 'form-horizontal' } do |f| %> - <%= f.input :_type %> + <%= f.association :election, label: '선거', collection: Election.all, :as => :radio_buttons %> <%= f.input :_id %> <%= f.input :name %> <%= f.input :party %> diff --git a/app/views/candidates/index.html.erb b/app/views/candidates/index.html.erb index 233bf24..0af89fd 100644 --- a/app/views/candidates/index.html.erb +++ b/app/views/candidates/index.html.erb @@ -8,6 +8,7 @@ <%= model_class.human_attribute_name(:name) %> <%= model_class.human_attribute_name(:party) %> + <%= model_class.human_attribute_name(:election) %> <%= model_class.human_attribute_name(:number) %> <%=t '.actions', :default => t("helpers.actions") %> @@ -17,6 +18,7 @@ <%= candidate.name %> <%= candidate.party %> + <%= candidate.election.title %> <%= candidate.number %> <%= link_to t('.edit', :default => t("helpers.links.edit")), @@ -35,4 +37,4 @@ <%= link_to t('.new', :default => t("helpers.links.new")), new_candidate_path, :class => 'btn btn-primary' %> - \ No newline at end of file + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1d39122..610eda7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,7 +15,7 @@ <% end %> - <%= content_for?(:title) ? yield(:title) : "2012 투표 대잔치" %> + <%= content_for?(:title) ? yield(:title) : "2017 투표 대잔치" %> <%= csrf_meta_tags %> @@ -44,6 +44,7 @@ <%= favicon_link_tag '/images/favicon.ico', :rel => 'shortcut icon' %> + <%= javascript_include_tag "application" %> @@ -62,16 +63,12 @@ <% end %>