Created
November 17, 2011 02:14
-
-
Save libin0120/1372180 to your computer and use it in GitHub Desktop.
Able to have CANCAN's new record attributes initialization feature when using inherit_resources
This file contains 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
CanCan::InheritedResource.class_eval do | |
# Copied from CACAN added attributes initialization for new_actions | |
def load_resource_instance | |
if parent? | |
@controller.send :association_chain | |
@controller.instance_variable_get("@#{instance_name}") | |
elsif new_actions.include? @params[:action].to_sym | |
# [[[ - initialize new object attributes according capability. | |
resource = @controller.send :build_resource | |
initial_attributes.each do |attr_name, value| | |
resource.send("#{attr_name}=", value) | |
end | |
@controller.send :resource | |
# ]]] | |
else | |
@controller.send :resource | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment