Skip to content

Instantly share code, notes, and snippets.

@jraczak
Created August 9, 2012 15:15
Show Gist options
  • Select an option

  • Save jraczak/3305046 to your computer and use it in GitHub Desktop.

Select an option

Save jraczak/3305046 to your computer and use it in GitHub Desktop.
#dwellings_controller.rb
class DwellingsController < ApplicationController
before_filter :signed_in_user
def index
@search = Sunspot.search do
fulltext params[:search]
end
@dwellings = @search.results
end
def show
@dwelling = Dwelling.find(params[:id])
end
def new
@dwelling = Dwelling.new
end
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."
end
redirect_to current_user
else
render 'new'
end
end
def destroy
end
end
#dwelling.rb
class Dwelling < ActiveRecord::Base
attr_accessible :street_address, :city, :state, :zip, :nickname
belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
has_many :roomies, :class_name => "User"
validates :street_address, presence: true
validates :city, presence: true
validates :state, presence: true
validates :zip, presence: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment