Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIP

  • Loading branch information...
commit d330a218a390ce7bf41d4cc2571c1600131af527 1 parent 16b9398
@jackquack authored
View
2  Gemfile
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
gem 'rails'
-gem 'sqlite3'
+gem 'mysql2'
gem 'parallel'
gem 'json'
gem 'has_scope'
View
4 Gemfile.lock
@@ -111,6 +111,7 @@ GEM
mime-types (1.21)
multi_json (1.7.2)
multipart-post (1.2.0)
+ mysql2 (0.3.11)
oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
@@ -190,7 +191,6 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.7)
squeel (1.0.18)
activerecord (~> 3.0)
activesupport (~> 3.0)
@@ -225,6 +225,7 @@ DEPENDENCIES
js-routes
json
kaminari
+ mysql2
nested_form!
omniauth-facebook
parallel
@@ -239,6 +240,5 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
sentient_user
simple_form (= 2.0.1)
- sqlite3
squeel
uglifier (>= 1.0.3)
View
5 app/controllers/bids_controller.rb
@@ -1,2 +1,7 @@
class BidsController < InheritedResources::Base
+ belongs_to :prediction, :optional => true
+ def create
+ params[:bid][:user_id] = current_user.id
+ create!
+ end
end
View
5 app/controllers/buys_controller.rb
@@ -1,2 +1,7 @@
class BuysController < InheritedResources::Base
+ belongs_to :prediction, :optional => true
+ def create
+ params[:buy][:user_id] = current_user.id
+ create!
+ end
end
View
2  app/controllers/predictions_controller.rb
@@ -1,6 +1,6 @@
class PredictionsController < InheritedResources::Base
def create
- params[:user_id] = current_user.id
+ params[:prediction][:user_id] = current_user.id
create!
end
end
View
4 app/models/bid.rb
@@ -1,3 +1,5 @@
class Bid < ActiveRecord::Base
- attr_accessible :price, :user_id
+ attr_accessible :price, :user_id, :prediction_id
+ belongs_to :prediction
+ belongs_to :user
end
View
2  app/models/buy.rb
@@ -1,3 +1,5 @@
class Buy < ActiveRecord::Base
attr_accessible :prediction_id, :price, :user_id
+ belongs_to :prediction
+ belongs_to :user
end
View
3  app/models/prediction.rb
@@ -1,3 +1,6 @@
class Prediction < ActiveRecord::Base
attr_accessible :end_date, :name, :prediction, :source, :verified_by
+ has_many :bids
+ has_many :buys
+ belongs_to :user
end
View
4 app/models/user.rb
@@ -2,6 +2,10 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
devise :omniauthable, :omniauth_providers => [:facebook]
+ has_many :predictions
+ has_many :bids
+ has_many :buys
+
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid, :name
# attr_accessible :title, :body
View
4 app/views/bids/_form.html.haml
@@ -9,8 +9,6 @@
.field
= f.label :price
= f.text_field :price
- .field
- = f.label :user_id
- = f.number_field :user_id
+ = f.hidden_field :prediction_id, :value => @prediction.id
.actions
= f.submit 'Save'
View
2  app/views/bids/show.html.haml
@@ -9,4 +9,4 @@
= link_to 'Edit', edit_bid_path(@bid)
\|
-= link_to 'Back', bids_path
+= link_to 'Back', prediction_path(@bid.prediction_id)
View
7 app/views/buys/_form.html.haml
@@ -9,11 +9,6 @@
.field
= f.label :price
= f.text_field :price
- .field
- = f.label :user_id
- = f.number_field :user_id
- .field
- = f.label :prediction_id
- = f.number_field :prediction_id
+ = f.hidden_field :prediction_id, :value => @prediction.id
.actions
= f.submit 'Save'
View
2  app/views/buys/show.html.haml
@@ -12,4 +12,4 @@
= link_to 'Edit', edit_buy_path(@buy)
\|
-= link_to 'Back', buys_path
+= link_to 'Back', prediction_path(@buy.prediction_id)
View
3  app/views/layouts/application.html.haml
@@ -1,13 +1,14 @@
!!!
%html
%head
- %title BitPredictor
+ %title BitPredictor - Predicting Your Bits Since 2013
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body
%p.notice= notice
%p.alert= alert
+ %h1 Prediction Done Right (kinda)
- if !current_user
= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook)
- else
View
57 app/views/predictions/show.html.haml
@@ -1,8 +1,5 @@
+%h1= @prediction.name
%p#notice= notice
-
-%p
- %b Name:
- = @prediction.name
%p
%b End date:
= @prediction.end_date
@@ -10,11 +7,53 @@
%b Prediction:
= @prediction.prediction
%p
- %b Source:
- = @prediction.source
-%p
- %b Verified by:
- = @prediction.verified_by
+ %b Created By:
+ = @prediction.user.name
+
+%h1 Place Your Bits
+%h2 Listing bids
+
+%table
+ %tr
+ %th Price
+ %th User
+ %th
+ %th
+ %th
+
+ - @prediction.bids.each do |bid|
+ %tr
+ %td= bid.price
+ %td= bid.user.name
+ %td= link_to 'Show', bid
+ %td= link_to 'Edit', edit_bid_path(bid)
+ %td= link_to 'Destroy', bid, :method => :delete, :data => { :confirm => 'Are you sure?' }
+
+%br
+= link_to 'New Bid', new_prediction_bid_path(@prediction.id)
+
+%h2 Listing buys
+
+%table
+ %tr
+ %th Price
+ %th User
+ %th Prediction
+ %th
+ %th
+ %th
+
+ - @prediction.buys.each do |buy|
+ %tr
+ %td= buy.price
+ %td= buy.user.name
+ %td= buy.prediction_id
+ %td= link_to 'Show', buy
+ %td= link_to 'Edit', edit_buy_path(buy)
+ %td= link_to 'Destroy', buy, :method => :delete, :data => { :confirm => 'Are you sure?' }
+
+%br
+= link_to 'New Buy', new_prediction_buy_path(@prediction.id)
= link_to 'Edit', edit_prediction_path(@prediction)
\|
View
30 config/database.yml
@@ -4,22 +4,34 @@
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
- adapter: sqlite3
- database: db/development.sqlite3
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: bitpredictor_development
pool: 5
- timeout: 5000
+ username: root
+ password: root
+ socket: /tmp/mysql.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
- adapter: sqlite3
- database: db/test.sqlite3
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: bitpredictor_test
pool: 5
- timeout: 5000
+ username: root
+ password: root
+ socket: /tmp/mysql.sock
production:
- adapter: sqlite3
- database: db/production.sqlite3
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: bitpredictor_production
pool: 5
- timeout: 5000
+ username: root
+ password: root
+ socket: /tmp/mysql.sock
View
9 config/routes.rb
@@ -1,11 +1,10 @@
BitPredictor::Application.routes.draw do
resources :buys
-
-
resources :bids
-
-
- resources :predictions
+ resources :predictions do
+ resources :buys
+ resources :bids
+ end
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks"}
View
12 db/schema.rb
@@ -14,19 +14,19 @@
ActiveRecord::Schema.define(:version => 20130323155754) do
create_table "bids", :force => true do |t|
- t.decimal "price"
+ t.decimal "price", :precision => 10, :scale => 0
t.integer "user_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.integer "prediction_id"
end
create_table "buys", :force => true do |t|
- t.decimal "price"
+ t.decimal "price", :precision => 10, :scale => 0
t.integer "user_id"
t.integer "prediction_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
create_table "predictions", :force => true do |t|
Please sign in to comment.
Something went wrong with that request. Please try again.