zeevallin / arcane

Rails strong parameters, made object oriented.
MIT License
50 stars 4 forks source link

Feature request: different roots for different actions #8

Open KonstantinKo opened 10 years ago

KonstantinKo commented 10 years ago

To get arcane to cooperate with the InheritedResources gem, I had to do a little metaprogramming trickery that allows an overwrite of the self.root method for each action because I didn't find a way to get the current action inside of the #root function. I think adding a reference point like that would make a good addition to the gem in general.

caulfield commented 10 years ago

What was the problem with this code?

def permitted_params
  params.for(resource).refine
end
KonstantinKo commented 10 years ago

IR permits params for the resources and build_resources of every action. In a #new action, for example, the build fails because the required root is not available unless I set it to false. If I do however the require is not present in the #create action.

caulfield commented 10 years ago

https://github.com/cloudsdaleapp/arcane/blob/master/lib/arcane/parameters.rb#L60

You can define .root or #root method in your refinery. self.action should be accessible from #root.

UPD. Sorry, This request is actual

zeevallin commented 9 years ago

I'm very sorry for the immense wait, not very nice of me to leave you hanging like this. What if you could specify a method in the chain to select the root key?

params.at(:published_article).refine