Skip to content

Instantly share code, notes, and snippets.

@kareemk
Created August 26, 2009 15:01
Show Gist options
  • Save kareemk/175554 to your computer and use it in GitHub Desktop.
Save kareemk/175554 to your computer and use it in GitHub Desktop.
def create
@tip = current_user.tips.build(params[:tip])
@option_string = params[:option_string] || ""
if @tip.valid?
# Try and lookup location if no direct match then prompt user with options
unless @tip.location_id
@locations = Location.find_all_by_name(@tip.location_name) || []
if @locations.empty?
@locations = Location.search(:conditions => {:name => @tip.location_name}, :star => true, :match_mode => :any)
end
if @locations.size == 1
@tip.location = @locations.first
else
@locations = @locations[0..MAX_LOCATION_CHOICES-1]
render :action => :set_location and return
end
end
else
render :action => :new and return
end
@tip.save!
flash[:notice] = "Tip successfully added!"
redirect_to mobile_tips_path
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment