Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
# These assume an application.rb method roughly equal to
#
# def current_user
# User.find(session[:user_id])
# end
#
# most basic example with the feature enabled
class UserController< ActionController::Base
load User
def show
redirect_to "/" unless user.is_active?
end
end
# much more complex with feature enabled
class MessagesController < ActionController::Base
load User, Message
def edit
redirect_to "/" if user != current_user
end
def update
if update_message
redirect_to message
end
message.errors.collect { BLAH }
render "edit"
end
end
end
# second complex example
class UserPreferencesController < ActionController::Base
load :current_user, Preferences
def create
preference = build_preference
if preference.save
# whateves
else
# whateves
end
end
end
# EQUIVALENT without the feature
class MessagesController < ActionController::Base
def edit
redirect_to "/" if user != current_user
end
def update
if update_message
redirect_to message
end
message.errors.collect { BLAH }
render "edit"
end
end
protected
def user
@user ||= User.find(params[:user_id])
end
helper_method :user
def message
@message ||= messages.find(params[:id])
end
helper_method :message
def messages
@messages ||= user.messages
end
helper_method :messages
def update_message
message.update_attribtues(params[:message])
end
def build_message
messages.build(params[:message])
end
end
class UserPreferencesController < ActionController::Base
def create
preference = build_preference
if preference.save
# whateves
else
# whateves
end
end
protected
def preference
@preference ||= current_user.preferences.find(params[:id])
end
helper_method :preference
def preferences
@preferences ||= current_user.preferences
end
helper_method :preferences
def update_preference
preference.update_attributes(params[:preference])
end
def build_preference
preferences.build(params[:preference])
end
end
|