Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

basic commenting in place

  • Loading branch information...
commit d1d730a655ca6d7eeb2c1bea9628d4efaba2dc42 1 parent 05710fe
@rahoulb rahoulb authored
View
1  app/controllers/codes_controller.rb
@@ -10,6 +10,7 @@ def index
def show
@code = Code.find_by_slug_name!(params[:slug_name])
+ @comment = Comment.new
rescue ActiveRecord::RecordNotFound
@codes = Code.find_with_ferret(["*", params[:slug_name], "*"].to_s)
View
11 app/controllers/comments_controller.rb
@@ -1,2 +1,13 @@
class CommentsController < ApplicationController
+ def create
+ @code = Code.find params[:code_id]
+ @comment = @code.build_comment params[:comment]
+ @comment.save!
+ flash[:notice] = 'Thanks for your comment'
+ redirect_to code_by_slug_path(@code.slug_name)
+
+ rescue ActiveRecord::RecordInvalid
+ render :template => 'codes/show'
+ flash[:error] = 'Sorry, unable to save your comment'
+ end
end
View
7 app/helpers/comments_helper.rb
@@ -1,2 +1,9 @@
module CommentsHelper
+ def name_link_for comment
+ if comment.url.blank?
+ h(comment.name)
+ else
+ "<a href=\"#{h(comment.url)}\">#{h(comment.name)}</a>"
+ end
+ end
end
View
19 app/models/code.rb
@@ -1,20 +1,10 @@
class Code < ActiveRecord::Base
-
- named_scope :last_thirty_active, :order => "updated_at DESC", :limit => 30
-
- validates_uniqueness_of :name, :slug_name
- validates_presence_of :name, :slug_name
-
has_many :authorships
has_many :authors, :through => :authorships
- has_many :comments, :dependent => :destroy
+ has_many :comments, :dependent => :destroy, :order => 'created_at desc'
has_many :working_comments, :class_name => 'Comment', :conditions => { :works_for_me => true }
has_many :failure_comments, :class_name => 'Comment', :conditions => { :works_for_me => false }
- acts_as_ferret :fields => [:name, :description, :homepage, :rubyforge, :github, :slug_name]
-
- before_validation_on_create :set_slug_name
-
def works?
has_no_failure_comments? && has_working_comments?
end
@@ -43,6 +33,13 @@ def self.new_from_gem_spec(spec)
private
+ validates_uniqueness_of :name, :slug_name
+ validates_presence_of :name, :slug_name
+
+ before_validation_on_create :set_slug_name
+
+ acts_as_ferret :fields => [:name, :description, :homepage, :rubyforge, :github, :slug_name]
+
def set_slug_name
self.slug_name = slug_name_from_name || self.rubyforge
end
View
5 app/models/comment.rb
@@ -1,3 +1,8 @@
class Comment < ActiveRecord::Base
belongs_to :code
+ belongs_to :platform
+
+private
+ validates_presence_of :code
+ validates_presence_of :platform
end
View
29 app/models/platform.rb
@@ -0,0 +1,29 @@
+class Platform < ActiveRecord::Base
+
+ def to_s
+ name
+ end
+
+ def self.load_defaults
+ add_entry_for 'Mac OSX 10.5'
+ add_entry_for 'Mac OSX 10.4'
+ add_entry_for 'Solaris'
+ add_entry_for 'Ubuntu Intrepid'
+ add_entry_for 'Ubuntu Hardy'
+ add_entry_for 'Ubuntu Dapper'
+ add_entry_for 'Fedora'
+ add_entry_for 'Suse'
+ add_entry_for 'Debian'
+ add_entry_for 'Gentoo'
+ add_entry_for 'RHEL'
+ add_entry_for 'Windows Vista'
+ add_entry_for 'Windows XP'
+ add_entry_for 'Windows 7'
+ end
+
+private
+
+ def self.add_entry_for platform
+ create! :name => platform unless Platform.find_by_name(platform)
+ end
+end
View
11 app/views/codes/show.html.erb
@@ -10,4 +10,13 @@
<p class="authors">
<%= h @code.author_names %>
-</p>
+</p>
+
+<p><%= link_to_function 'add a comment &rarr;', visual_effect(:toggle_blind, 'new-comment-form') %> </p>
+<div id="new-comment-form" style="display:none">
+ <%= render :partial => 'comments/new', :locals => { :code => @code } %>
+</div>
+
+
+<%= render :partial => 'comments/comment', :collection => @code.comments %>
+
View
5 app/views/comments/_comment.html.erb
@@ -0,0 +1,5 @@
+<% if comment.works_for_me? %>
+ <%= render :partial => 'comments/working_comment', :object => comment %>
+<% else %>
+ <%= render :partial => 'comments/failed_comment', :object => comment %>
+<% end %>
View
6 app/views/comments/_failed_comment.html.erb
@@ -0,0 +1,6 @@
+<% div_for failed_comment, :class => 'failed' do %>
+ <p class="status">Reported as failing on <%= failed_comment.platform %> by <%= name_link_for failed_comment %></p>
+ <% unless failed_comment.body.blank? %>
+ <p class="comment"> <%= h failed_comment.body %> </p>
+ <% end %>
+<% end %>
View
10 app/views/comments/_new.html.erb
@@ -0,0 +1,10 @@
+<% form_for [code, @comment] do | form | %>
+ <%= error_messages_for :comment %>
+ <ul>
+ <li> <%= form.check_box :works_for_me %> <%= form.label :works_for_me %> </li>
+ <li> <%= form.label :body, "Comments: " %> <br/> <%= form.text_area :body, :rows => 3 %> </li>
+ <li> <%= form.label :platform_id %> <br/> <%= form.collection_select :platform_id, Platform.all, :id, :name %> </li>
+ <li> <%= form.label :name %> <br/> <%= form.text_field :name %> </li>
+ <li> <%= form.label :url %> <br/> <%= form.text_field :url %> </li>
+ <li> <%= submit_tag 'Submit &rarr;', :disable_with => 'submitting...' %></li>
+<% end %>
View
6 app/views/comments/_working_comment.html.erb
@@ -0,0 +1,6 @@
+<% div_for working_comment, :class => 'working' do %>
+ <p class="status">Reported as working on <%= working_comment.platform %> by <%= name_link_for working_comment %> on <%= working_comment.created_at.to_s %></p>
+ <% unless working_comment.body.blank? %>
+ <p class="comment"> <%= h working_comment.body %> </p>
+ <% end %>
+<% end %>
View
3  app/views/layouts/isitruby19.html.erb
@@ -29,6 +29,9 @@
<% unless flash[:notice].blank? %>
<div id="flash_notice"> <%= flash[:notice] %> </div>
<% end %>
+ <% unless flash[:error].blank? %>
+ <div id="flash_error"> <%= flash[:error] %> </div>
+ <% end %>
&nbsp;
<% form_tag codes_path, :method => :get, :id => 'search-form' do %>
<%= text_field_tag :search, params[:search] %> <%= submit_tag 'Search &rarr;', :disable_with => 'searching....' %>
View
2  db/migrate/20090131234053_create_codes.rb
@@ -1,7 +1,7 @@
class CreateCodes < ActiveRecord::Migration
def self.up
create_table :codes do |t|
- t.string :name, :description, :homepage, :rubyforge, :github, :type
+ t.string :name, :description, :homepage, :rubyforge, :github, :type, :slug_name
t.decimal :latest_version
t.timestamps
end
View
6 db/migrate/20090131234059_create_comments.rb
@@ -1,12 +1,14 @@
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
- t.references :code, :user
+ t.references :code, :platform
t.text :body
t.boolean :works_for_me
- t.string :platform
+ t.string :name, :url
t.timestamps
end
+
+ add_index :comments, :code_id
end
def self.down
View
22 db/migrate/20090131234446_create_users.rb
@@ -1,22 +0,0 @@
-class CreateUsers < ActiveRecord::Migration
- def self.up
- create_table :users do |t|
- t.string :name
- t.string :email
- t.string :homepage
- t.string :login, :null => false
- t.string :crypted_password, :null => false
- t.string :password_salt, :null => false
- t.string :persistence_token, :null => false
- t.string :single_access_token, :null => false # optional, see the tokens section below.
- t.string :perishable_token, :null => false # optional, see the tokens section below.
- t.integer :login_count, :null => false, :default => 0 # optional, this is a "magic" column, see the magic columns section below
- t.timestamps
- t.boolean :is_admin
- end
- end
-
- def self.down
- drop_table :users
- end
-end
View
9 db/migrate/20090201000927_add_slug_to_codes.rb
@@ -1,9 +0,0 @@
-class AddSlugToCodes < ActiveRecord::Migration
- def self.up
- add_column :codes, :slug_name, :string
- end
-
- def self.down
- remove_column :codes, :slug_name
- end
-end
View
13 db/migrate/20090202151412_create_platforms.rb
@@ -0,0 +1,13 @@
+class CreatePlatforms < ActiveRecord::Migration
+ def self.up
+ create_table :platforms do |t|
+ t.string :name
+ t.timestamps
+ end
+ add_index :platforms, :name
+ end
+
+ def self.down
+ drop_table :platforms
+ end
+end
View
19 db/migrate/20090202155040_add_various_indexes.rb
@@ -0,0 +1,19 @@
+class AddVariousIndexes < ActiveRecord::Migration
+ def self.up
+ add_index :authors, :name
+ add_index :authorships, :code_id
+ add_index :authorships, :author_id
+ add_index :codes, :name
+ add_index :codes, :updated_at
+ add_index :comments, :created_at
+ end
+
+ def self.down
+ remove_index :authors, :name
+ remove_index :authorships, :code_id
+ remove_index :authorships, :author_id
+ remove_index :codes, :name
+ remove_index :codes, :updated_at
+ remove_index :comments, :created_at
+ end
+end
View
34 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090202123742) do
+ActiveRecord::Schema.define(:version => 20090202155040) do
create_table "authors", :force => true do |t|
t.string "name"
@@ -17,6 +17,8 @@
t.datetime "updated_at"
end
+ add_index "authors", ["name"], :name => "index_authors_on_name"
+
create_table "authorships", :force => true do |t|
t.integer "author_id"
t.integer "code_id"
@@ -24,6 +26,9 @@
t.datetime "updated_at"
end
+ add_index "authorships", ["author_id"], :name => "index_authorships_on_author_id"
+ add_index "authorships", ["code_id"], :name => "index_authorships_on_code_id"
+
create_table "codes", :force => true do |t|
t.string "name"
t.string "description"
@@ -31,36 +36,35 @@
t.string "rubyforge"
t.string "github"
t.string "code_type"
+ t.string "slug_name"
t.decimal "latest_version"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "slug_name"
end
+ add_index "codes", ["name"], :name => "index_codes_on_name"
+ add_index "codes", ["updated_at"], :name => "index_codes_on_updated_at"
+
create_table "comments", :force => true do |t|
t.integer "code_id"
- t.integer "user_id"
+ t.integer "platform_id"
t.text "body"
t.boolean "works_for_me"
- t.string "platform"
+ t.string "name"
+ t.string "url"
t.datetime "created_at"
t.datetime "updated_at"
end
- create_table "users", :force => true do |t|
+ add_index "comments", ["code_id"], :name => "index_comments_on_code_id"
+ add_index "comments", ["created_at"], :name => "index_comments_on_created_at"
+
+ create_table "platforms", :force => true do |t|
t.string "name"
- t.string "email"
- t.string "homepage"
- t.string "login", :null => false
- t.string "crypted_password", :null => false
- t.string "password_salt", :null => false
- t.string "persistence_token", :null => false
- t.string "single_access_token", :null => false
- t.string "perishable_token", :null => false
- t.integer "login_count", :default => 0, :null => false
t.datetime "created_at"
t.datetime "updated_at"
- t.boolean "is_admin"
end
+ add_index "platforms", ["name"], :name => "index_platforms_on_name"
+
end
View
4 lib/tasks/isitruby19.rake
@@ -3,4 +3,8 @@ namespace :isitruby19 do
task :import => :environment do
GemImporter.import
end
+
+ task :load_platforms => :environment do
+ Platform.load_defaults
+ end
end
View
8 test/unit/platform_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class PlatformTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.