Skip to content

Instantly share code, notes, and snippets.

View jraczak's full-sized avatar

Justin Raczak jraczak

View GitHub Profile
if defined?(WillPaginate)
module WillPaginate
module ActiveRecord
module RelationMethods
alias_method :per, :per_page
alias_method :num_pages, :total_pages
alias_method :total_count, :count
end
end
end
# -*- coding: utf-8 -*-
module ApplicationHelper
# Public: Generates a resource's error messages as a sentence, wrapped in an
# alert message.
#
# resource - An ActiveModel-compliant object
#
# Examples
#
# -*- coding: utf-8 -*-
module ApplicationHelper
# Public: Generates a resource's error messages as a sentence, wrapped in an
# alert message.
#
# resource - An ActiveModel-compliant object
#
# Examples
#
<<< Query venue for venue scores, select user_ids from returned venue_scores >>>
1.9.3-p125 :011 > venue.venue_scores.all(:select => :user_id)
VenueScore Load (23.2ms) SELECT user_id FROM "venue_scores" WHERE "venue_scores"."venue_id" = 5
=> [#<VenueScore user_id: 1>, #<VenueScore user_id: 2>]
@jraczak
jraczak / gist:2656268
Created May 10, 2012 22:20
Calculating social cues for venue scores
# Find count of users followed by current user that have submitted scores to Venue
def find_social_scores(venue)
followed_user_ids = self.follows.map { |user|
user.id
}
venue_score_ids = venue.venue_scores.map { |score|
score.user_id
}
(followed_user_ids & venue_score_ids).count
end
@jraczak
jraczak / gist:2956622
Created June 19, 2012 21:22
Error Output for Rails_Admin "list" function
ArgumentError in Rails_admin/main#index
Showing /Volumes/UserData/Users/jraczak/.rvm/gems/ruby-1.9.3-p125@crowdscore/gems/rails_admin-0.0.1/app/views/rails_admin/main/index.html.haml where line #139 raised:
wrong number of arguments (2 for 1)
Extracted source (around line #139):
136: = paginate(@objects, :theme => 'twitter-bootstrap', :remote => true)
137: = link_to(t("admin.misc.show_all"), index_path(params.merge(:all => true)), :class => "show-all btn clearfix pjax") unless total_count > 100 || total_count <= @objects.to_a.size
@jraczak
jraczak / gist:3232410
Created August 2, 2012 01:56
Error during Dwelling Create action.
**ERROR**
NoMethodError in DwellingsController#create
undefined method `build' for nil:NilClass
Rails.root: /Volumes/UserData/Users/jraczak/Desktop/Everything/rails_projects/roomie
Application Trace | Framework Trace | Full Trace
app/controllers/dwellings_controller.rb:14:in `create'
**/ERROR**
NoMethodError in DwellingsController#index
undefined method `search' for #<Class:0x0000010299cf70>
def index
@search = Dwelling.search do
fulltext params[:search]
end
@dwellings = @search.results
end
ArgumentError in DwellingsController#index
You must specify at least one type to search