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 %>
<% if user_signed_in? %>
@@ -93,8 +90,8 @@
|