Skip to content

Instantly share code, notes, and snippets.

@iamjwc
Created March 16, 2009 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iamjwc/80014 to your computer and use it in GitHub Desktop.
Save iamjwc/80014 to your computer and use it in GitHub Desktop.
# Controller
class GuestsController < ApplicationController
def create
@guest = Guest.new(params[:guest])
if @guest.save
redirect_to :action => 'index'
else
render :action => 'new'
end
end
end
# Model
class Guest
validates_presence_of :student_id
def student_name=(name)
student = Student.find_by_name(name)
self.student_id = student.id unless student.nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment