Skip to content

Commit

Permalink
No longer require people to login.
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Sep 16, 2008
1 parent 873837d commit 1953dac
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 62 deletions.
17 changes: 14 additions & 3 deletions app/controllers/twonks_controller.rb
Expand Up @@ -14,9 +14,9 @@ def new

def create
@twonk = current_user.nominations.new(params[:twonk])
@twonk.votes_count = 1
puts current_user
if @twonk.save
@vote = @twonk.votes.create(:user => current_user, :comment => params[:vote][:comment])
@vote = @twonk.votes.create(params[:vote].merge(:ip => current_user))
flash[:success] = "Twonk has been nominated!"
redirect_to twonk_path(@twonk)
else
Expand All @@ -41,17 +41,28 @@ def update

def show
@twonk = Twonk.find(params[:id], :include => [:for_votes, :against_votes, :votes])
rescue ActiveRecord::RecordNotFound
not_found
end

def destroy
@twonk.destroy
flash[:success] = "#{@twonk} has been untwonked!"
redirect_to twonks_path
end

def check_for_ownership
@twonk = Twonk.find(params[:id])
unless @twonk.nominated_by == current_user
flash[:notice] = "That is not your twonk to change!"
redirect_back_or_default(twonks_path)
end
end
rescue ActiveRecord::RecordNotFound
not_found
end

def not_found
flash[:failure] = "The twonk you were looking for no longer exists, or never existed."
redirect_to twonks_path
end
end
2 changes: 1 addition & 1 deletion app/controllers/votes_controller.rb
Expand Up @@ -44,7 +44,7 @@ def update
private

def check_for_ownership
unless @vote.user == current_user
unless @vote.ip == current_user
flash[:failure] = "That vote does not belong to you, you twonk!"
redirect_to twonk_path(@twonk)
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/ip.rb
@@ -0,0 +1,3 @@
class Ip < ActiveRecord::Base
has_many :nominations, :class_name => "Twonk", :foreign_key => "nominated_by_id"
end
7 changes: 5 additions & 2 deletions app/models/twonk.rb
Expand Up @@ -2,10 +2,13 @@ class Twonk < ActiveRecord::Base
has_many :votes
has_many :for_votes, :class_name => "Vote", :conditions => "positive = TRUE"
has_many :against_votes, :class_name => "Vote", :conditions => "positive = FALSE"
has_many :voters, :through => :votes, :source => :user
belongs_to :nominated_by, :class_name => "User"
has_many :voters, :through => :votes, :source => :ip
belongs_to :nominated_by, :class_name => "Ip", :counter_cache => "nomination_count"
attr_accessible :name, :location
validates_presence_of :name, :location
validates_uniqueness_of :name, :scope => :location

def to_s
name
end
end
8 changes: 1 addition & 7 deletions app/models/vote.rb
@@ -1,15 +1,9 @@
class Vote < ActiveRecord::Base
belongs_to :twonk
belongs_to :user, :counter_cache => "nomination_count"
# acts_as_snook :author_field => :user, :body_field => :comment

belongs_to :ip
before_save :change_vote_count

def change_vote_count
(positive? ? twonk.increment!("votes_count") : twonk.decrement!("votes_count")) if positive_changed? || new_record?
end

def url

end
end
12 changes: 3 additions & 9 deletions app/views/layouts/application.html.erb
Expand Up @@ -5,15 +5,9 @@
</head>
<body>
<div id='menu'>
<% if logged_in? %>
<b><%= link_to "Nominate New Twonk!", new_twonk_path %></b> |
<%= link_to "Your Nominations", your_twonks_path %> |
<%= link_to "Logout", logout_path %>
<% else %>
<%= link_to "Login", login_path %> |
<%= link_to "Signup", signup_path %>
<% end %>
| <%= link_to "About", about_path %>
<b><%= link_to "Nominate New Twonk!", new_twonk_path %></b> |
<%= link_to "Your Nominations", your_twonks_path %> |
<%= link_to "About", about_path %>
</div>
<div id="header">
<%= link_to image_tag((params[:controller] == 'twonks' && params[:action] == 'index') ? "twonklist.jpg" : "twonklist_small.jpg"), root_path %><br />
Expand Down
22 changes: 20 additions & 2 deletions app/views/votes/_vote.html.erb
@@ -1,9 +1,27 @@
<div class='number' align='left'>
#<%= vote_counter %> <% if vote.user == current_user %> You! - <%= link_to "Edit", edit_twonk_vote_path(vote.twonk, vote) %><% end %>
#<%= vote_counter %> <% if vote.ip == current_user %> You! - <%= link_to "Edit", edit_twonk_vote_path(vote.twonk, vote) %><% end %>
<br>
<%= image_tag "quote-bubble.jpg", :class => "quote-bubble" %>
</div>
<%= render :partial => "votes/" + (vote.user == current_user ? "mine" : "yours"), :locals => { :vote => vote } %>
<span>
<b class="spiffy">
<b class="spiffy1"><b></b></b>
<b class="spiffy2"><b></b></b>
<b class="spiffy3"></b>
<b class="spiffy4"></b>
<b class="spiffy5"></b></b>

<div class="spiffyfg">
<%= (h vote.comment).gsub("\n", "<br>") %>
</div>

<b class="spiffy">
<b class="spiffy5"></b>
<b class="spiffy4"></b>
<b class="spiffy3"></b>
<b class="spiffy2"><b></b></b>
<b class="spiffy1"><b></b></b></b>
</span>

<div class="vote-end"></div>

Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20080916002038_create_ips.rb
@@ -0,0 +1,16 @@
class CreateIps < ActiveRecord::Migration
def self.up
# drop_table :users
# create_table :ips do |t|
# t.integer :nomination_count, :default => 0
# t.string :ip
# end
rename_column :votes, :user_id, :ip_id
end

def self.down
drop_table :ips
create_table :users do |t|
end
end
end
2 changes: 1 addition & 1 deletion lib/authenticated_system.rb
Expand Up @@ -9,7 +9,7 @@ def logged_in?
# Accesses the current user from the session.
# Future calls avoid the database because nil is not equal to false.
def current_user
@current_user ||= (login_from_session || login_from_basic_auth || login_from_cookie) unless @current_user == false
Ip.find_or_create_by_ip(request.remote_addr)
end

# Store the given user id in the session.
Expand Down
37 changes: 0 additions & 37 deletions public/stylesheets/style.css
Expand Up @@ -122,40 +122,3 @@ div.number { margin-bottom: -4px; }
padding:5px;
width:490px;
}


.my-spiffy * {
background:#F7B30A;
}

.my-spiffy1 {
border-left:1px solid #7e6018;
border-right:1px solid #7e6018;
background:#c28f10;
}

.my-spiffy2 {
border-left:1px solid #383120;
border-right:1px solid #383120;
background:#ce970e;
}

.my-spiffy3 {
border-left:1px solid #ce970e;
border-right:1px solid #ce970e;
}

.my-spiffy4 {
border-left:1px solid #7e6018;
border-right:1px solid #7e6018;
}

.my-spiffy5 {
border-left:1px solid #c28f10;
border-right:1px solid #c28f10;
}

.my-spiffyfg {
background:#F7B30A;
color:black;
}
7 changes: 7 additions & 0 deletions test/fixtures/ips.yml
@@ -0,0 +1,7 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

# one:
# column: value
#
# two:
# column: value
8 changes: 8 additions & 0 deletions test/unit/ip_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class IpTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end

0 comments on commit 1953dac

Please sign in to comment.