Skip to content

Instantly share code, notes, and snippets.

View jraczak's full-sized avatar

Justin Raczak jraczak

View GitHub Profile
#dwellings_controller.rb
class DwellingsController < ApplicationController
before_filter :signed_in_user
def index
@search = Sunspot.search do
fulltext params[:search]
end
@dwellings = @search.results
#dwellings_controller.rb
def create
@dwelling = current_user.properties.build(params[:dwelling])
if @dwelling.save
current_user.dwelling = @dwelling
if current_user.save
flash[:success] = "Woohoo! Your dwelling has been created. Welcome home!"
else
flash[:notice] = "You have successfully created a dwelling, but something prevented us from adding you as a roomie. Please email support so we can try to correct this for you."
@jraczak
jraczak / gist:3342220
Created August 13, 2012 16:08
Solr Search for Dwellings
#dwellings_controller.rb
def index
@result = Dwelling.search("545")
@dwellings = @results.result
puts @dwellings.to_yaml
end
#dwelling.rb
source 'https://rubygems.org'
gem 'rails', '3.2.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'devise'
gem 'simple_form'
$ se = SharedExpense.last
SharedExpense Load (0.1ms) SELECT "shared_expenses".* FROM "shared_expenses" ORDER BY "shared_expenses"."id" DESC LIMIT 1
=> #<SharedExpense id: 2, name: "Paper Towel", stocked: true, last_purchased: nil, dwelling_id: 1, user_id: 1, created_at: "2012-10-10 21:55:59", updated_at: "2012-10-10 22:01:51">
$ se.user_id = 2
=> 2
$ se
=> #<SharedExpense id: 2, name: "Paper Towel", stocked: true, last_purchased: nil, dwelling_id: 1, user_id: 2, created_at: "2012-10-10 21:55:59", updated_at: "2012-10-10 22:01:51">
$ SharedExpense.last
SharedExpense Load (0.2ms) SELECT "shared_expenses".* FROM "shared_expenses" ORDER BY "shared_expenses"."id" DESC LIMIT 1
=> #<SharedExpense id: 2, name: "Paper Towel", stocked: true, last_purchased: nil, dwelling_id: 1, user_id: 1, created_at: "2012-10-10 21:55:59", updated_at: "2012-10-10 22:01:51">
# ORIGINAL METHOD
def change_owner
@shared_expense = SharedExpense.find(params[:id])
current_owner = @shared_expense.user
roomies = @shared_expense.dwelling.roomies.sort_by { |roomie| roomie.id }
next_owner_index = roomies.index {|roomie| roomie.id == current_owner.id} + 1
next_owner = roomies[next_owner_index]
@shared_expense.user_id = next_owner.id
@shared_expense.save
redirect_to current_user.dwelling
if roomies[next_owner_index] != nil
@shared_expense.user_id = roomies[next_owner_index].id #next_owner.id
else
@shared_expense.user_id = roomies[0].id
end
<%= f.input :user_id, collection: current_user.dwelling.roomies.all, label_method: :full_name, selected: current_user.id %>
crowdscore (master) $ gem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/jraczak/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for libxml/parser.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
# abstracted code selection from tip.rb
# 'date_age' is named arbitrarily
def as_json(options = nil)
methods = []
methods << :can_upvote if @current_user_id.present?
methods << :date_age
super(methods: methods, include: { user: { only: :username } })
end