Permalink
Browse files

added lotteryticket + user + group insert functionality

  • Loading branch information...
1 parent 084a125 commit baacc85da0cc67de3ba7025472239e97a6049e4c @nishantpant committed Apr 9, 2012
View
@@ -29,7 +29,8 @@ gem 'yaml_db'
gem 'feedzirra'
gem 'thin'
gem "jquery-rails"
-gem 'haml'
+gem 'authlogic'
+gem "rails3-generators"
group :production do
# gem 'therubyracer-heroku'
View
@@ -29,6 +29,9 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
+ authlogic (3.1.0)
+ activerecord (>= 3.0.7)
+ activerecord (>= 3.0.7)
builder (3.0.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
@@ -53,7 +56,6 @@ GEM
rake (>= 0.9.2)
rdoc (~> 3.8)
sax-machine (~> 0.0.20)
- haml (3.1.4)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
@@ -94,6 +96,8 @@ GEM
bundler (~> 1.0)
railties (= 3.2.2)
rails-dbi (0.1.2)
+ rails3-generators (0.17.4)
+ railties (>= 3.0.0)
railties (3.2.2)
actionpack (= 3.2.2)
activesupport (= 3.2.2)
@@ -140,16 +144,17 @@ PLATFORMS
x86-mingw32
DEPENDENCIES
+ authlogic
coffee-rails (~> 3.2.1)
execjs
feedzirra
- haml
jquery-rails
jquery-ui-rails
json
pg
rails (= 3.2.2)
rails-dbi
+ rails3-generators
ruby-odbc
sass-rails (~> 3.2.3)
sqlite3
@@ -1,3 +1,14 @@
class ApplicationController < ActionController::Base
protect_from_forgery
-end
+ helper_method :current_user
+
+ private
+ def current_user_session
+ return @current_user_session if defined?(@current_user_session)
+ @current_user_session = UserSession.find
+ end
+
+ def current_user
+ @current_user = current_user_session && current_user_session.record
+ end
+ end
@@ -1,4 +1,4 @@
-class GroupController < ApplicationController
+class GroupsController < ApplicationController
def show
@group = Group.find(params[:id])
@users = @group.users.all
@@ -30,15 +30,15 @@ def edit
# POST /users
# POST /users.json
def create
- @group = Group.new(params[:user])
+ @group = Group.new(params[:group])
respond_to do |format|
- if @Group.save
+ if @group.save
format.html { redirect_to @group, :notice => 'Group was successfully created.' }
format.json { render :json => @group, :status => :created, :location => @group}
else
format.html { render :action => "new" }
- format.json { render :json => @Group.errors, :status => :unprocessable_entity }
+ format.json { render :json => @group.errors, :status => :unprocessable_entity }
end
end
end
@@ -49,12 +49,12 @@ def update
@group = Group.find(params[:id])
respond_to do |format|
- if @Group.update_attributes(params[:user])
+ if @group.update_attributes(params[:group])
format.html { redirect_to @group, :notice => 'Group was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
- format.json { render :json => @Group.errors, :status => :unprocessable_entity }
+ format.json { render :json => @group.errors, :status => :unprocessable_entity }
end
end
end
@@ -1,94 +0,0 @@
-class LotteryticketController < ApplicationController
- def show
- @lotteryticket = Lotteryticket.find(params[:id])
- @groups = Group.all
- respond_to do |format|
- format.html # show.html.erb
- format.json { render :json => @lotteryticket }
- end
- end
-
- # GET /users/new
- # GET /users/new.json
- def new
- @lotteryticket = Lotteryticket.new
- @groups = Group.all
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render :json => @lotteryticket }
- end
- end
-
- # GET /users/1/edit
- def edit
- @lotteryticket = Lotteryticket.find(params[:id])
- @groups = Group.all
- end
-
- # POST /users
- # POST /users.json
- def create
- @lotteryticket = Lotteryticket.new(params[:user])
-
- respond_to do |format|
- if @lotteryticket.save
- format.html { redirect_to @lotteryticket, :notice => 'Lottery Ticket was successfully created.' }
- format.json { render :json => @lotteryticket, :status => :created, :location => @lotteryticket}
- else
- format.html { render :action => "new" }
- format.json { render :json => @lotteryticket.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # PUT /users/1
- # PUT /users/1.json
- def update
- @lotteryticket = Lotteryticket.find(params[:id])
-
- respond_to do |format|
- if @lotteryticket.update_attributes(params[:user])
- format.html { redirect_to @lotteryticket, :notice => 'Lottery Ticket was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render :action => "edit" }
- format.json { render :json => @lotteryticket.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # DELETE /users/1
- # DELETE /users/1.json
- def destroy
- @lotteryticket = Lotteryticket.find(params[:id])
- @lotteryticket.destroy
-
- respond_to do |format|
- format.html { redirect_to users_url }
- format.json { head :no_content }
- end
- end
-
- def index
- @lotterytickets = Lotteryticket.all
- @rss = getLottoRss
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render :json => @lotterytickets }
- end
- end
-
- def getLottoRss
- require 'feedzirra'
- feed = Feedzirra::Feed.fetch_and_parse("http://www.txlottery.org/export/sites/lottery/rss/tlc_latest.xml")
- feed.entries.each do |entry|
- if(entry.url == 'http://www.txlottery.org/export/sites/default/Games/Mega_Millions/' &&
- entry.title.index("Mega Millions Winning Numbers for") != nil)
- return entry
- end
- end
-
- end
-end
@@ -1,6 +1,6 @@
-class UserController < ApplicationController
+class UsersController < ApplicationController
def show
- @user = User.find(params[:id])
+ @user = User.find((params[:id]))
@groups = @user.groups
respond_to do |format|
@@ -22,7 +22,7 @@ def new
# GET /users/1/edit
def edit
- @user = User.find(params[:id])
+ @user = User.find((params[:id]))
@groups = Group.all
end
@@ -45,7 +45,7 @@ def create
# PUT /users/1
# PUT /users/1.json
def update
- @user = User.find(params[:id])
+ @user = User.find((params[:id]))
respond_to do |format|
if @user.update_attributes(params[:user])
@@ -57,7 +57,7 @@ def update
if r == nil
group = Group.find(id)
group.users << @user
- group.users.save
+ group.save
end
end
end
@@ -75,7 +75,7 @@ def update
# DELETE /users/1
# DELETE /users/1.json
def destroy
- @users = User.find(params[:id])
+ @users = User.find((params[:id]))
@users.destroy
respond_to do |format|
View
@@ -1,3 +1,4 @@
class User < ActiveRecord::Base
+ acts_as_authentic
has_and_belongs_to_many :groups
end
@@ -1,2 +0,0 @@
-<h1>Group#new</h1>
-<p>Find me in app/views/group/new.html.erb</p>
File renamed without changes.
@@ -27,8 +27,9 @@
<td>$<%= group.dollar_amount %></td>
<td><%= group.lotterytickets.count %></td>
<td>
- <%= link_to 'Show', group %>
- <%= link_to 'Edit', edit_group_path(group) %>
+ <%= link_to 'Show ', group %>|
+ <%= link_to 'Edit ', edit_group_path(group) %>|
+ <%= link_to 'New', new_group_path %>
</td>
</tr>
<% end %>
@@ -0,0 +1,60 @@
+<div style="padding: 20px 180px;">
+<h1>New Group</h1>
+
+<%= form_for @group do |form| %>
+ <% if @group.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@group.errors.count, "error") %> prohibited this group from being saved:</h2>
+
+ <ul>
+ <% @group.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <table id="items" border="0">
+ <tr>
+ <td>
+ <%= form.label :name, "Name" %>
+ </td>
+ <td>
+ <%= form.text_field :name %>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <%= form.label :description, "Description" %>
+ </td>
+ <td>
+ <%= form.text_field :description %>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <%= form.label :lottery_date, "Lottery Date" %>
+ </td>
+ <td>
+ <%= form.text_field :lottery_date %>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <%= form.label :dollar_amount, "Dollar Amount" %>
+ </td>
+ <td>
+ <%= form.text_field :dollar_amount %>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <%= form.submit "Submit", :class =>"button" %>
+ </td>
+ </tr>
+ </table>
+ </div>
+<% end %>
+
+<%= link_to 'Back', groups_path %>
File renamed without changes.
@@ -24,13 +24,13 @@
<a href="/">Home</a>
</li>
<li id="menu-item-12" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-12">
- <a href="/group/index">Pools</a>
+ <a href="/groups">Pools</a>
</li>
<li id="menu-item-13" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-13">
- <a href="/user/index">Members</a>
+ <a href="/users">Members</a>
</li>
<li id="menu-item-951" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-951">
- <a href="/user/index">My Account</a>
+ <a href="/users">My Account</a>
</li>
</ul>
</div>
@@ -59,13 +59,19 @@
<a href="/">Home</a>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-12">
- <a href="/group/index">Pools</a>
+ <a href="/groups">Pools</a>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-13">
- <a href="/user/index">Members</a>
+ <a href="/users">Members</a>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-951">
- <a href="/user/index">My Account</a>
+ <% if current_user %>
+ <%= link_to "Edit profile", edit_user_path(:current) %>
+ <%= link_to "Logout", logout_path %>
+ <% else %>
+ <%= link_to "Register", new_user_path %>
+ <%= link_to "Log in", login_path %>
+ <% end %>
</li>
</ul>
</div>
@@ -1,2 +0,0 @@
-<h1>Lotteryticket#destroy</h1>
-<p>Find me in app/views/lotteryticket/destroy.html.erb</p>
@@ -1,2 +0,0 @@
-<h1>Lotteryticket#edit</h1>
-<p>Find me in app/views/lotteryticket/edit.html.erb</p>
Oops, something went wrong.

0 comments on commit baacc85

Please sign in to comment.