Created
March 28, 2011 23:02
-
-
Save mrmemes-eth/891504 to your computer and use it in GitHub Desktop.
A default exposure for decent_exposure that assigns instance variables (to make cancan happy)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default_exposure do |name| | |
collection = name.to_s.pluralize | |
if respond_to?(collection) && collection != name.to_s && send(collection).respond_to?(:scoped) | |
proxy = send(collection) | |
else | |
proxy = name.to_s.classify.constantize | |
end | |
instance_variable_set("@#{name}") = if id = params["#{name}_id"] || params[:id] | |
proxy.find(id).tap do |r| | |
r.attributes = params[name] unless request.get? | |
end | |
else | |
proxy.new(params[name]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment