Skip to content

Instantly share code, notes, and snippets.

@jarodl
Forked from iamjwc/gist:80014
Created March 16, 2009 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarodl/80021 to your computer and use it in GitHub Desktop.
Save jarodl/80021 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