Improve part() syntax, and why are part_controller actions' args not in action_argument_list?
Reported by Shay Arnett | February 11th, 2008 @ 08:34 PM | in 1.0
Originally posted on Trac by ben@ducktyped.com
Description
I was looking into a way to send parameters to parts. A basic way to do this right now is this:
class Post :show) # can be included in view template
render
end
end
class MyPart
I find this kind of ugly and inconvenient, and I'd prefer to have a syntax like:
part(MyPart, :show, { :part_param => "This is part-time only" })
part(klass, method, opts={})
I patched Merb::Controller#part to add all passed opts to the params hash, so that the PartController action can access them.
So far so good. This works and has minimal overhead. The one thing I've been trying to hack in with no success so far is to get the controller action arguments syntax sugar that allows you to write
def show(stuff = "too much")
@stuff = stuff
end
instead of
def show
@stuff = params[:stuff] || "too much"
end
After my scavenger hunt through the controller/dispatching code, I've found out the following:
The magic for the action(args) sugar happens in AbstractController#call_action. All actions are routed through it. call_action uses an action_argument_list, which is a nested array that holds each controller.action's argument list and possible defaults, e.g. [[:x, 0], [:y]] => action(x=0, y). This array is built at startup from Merb::Server#load_application.
This is where I either don't understand the code well enough yet or it's a bug of sorts. Although PartControllers inherit from AbstractControllers, their actions are not included in the action_argument_list. Are they considered non-callable? Is there some scoping or security issue that I'm overlooking?
Let's discuss to see if this could become a patch or if the project has other plans for parts.
I think it would be cool to be able to call this:
part(TagCloud, :show, { :num_tags => 25 })
Trac Attachments
Trac Comments
12/14/07 04:51:02 changed by has.sox@gmail.com
There is another benefit to being able to pass a parameters hash to the part controller. Action Caching.
I agree that it would be nice to have parts given the parameterized actions, and also be able to pass the params hash.
Comments and changes to this ticket
-
Yehuda Katz (wycats) February 28th, 2008 @ 08:10 PM
- → Milestone changed from to 0.9.4
- → Assigned user changed from to Yehuda Katz (wycats)
- → State changed from new to open
-
Daniel Parker April 1st, 2008 @ 06:32 PM
I have a similar concern that I think falls under the direction this fix is going.
I've made some plugins that include controllers, perhaps one that adds a method to an existing controller, and that doesn't work with the current way action_arguments are loaded in the bootloader.
Along with the existing concerns of this ticket, I was left with this thought: Could the action_arguments be gathered on a ruby hook such as method_added to classes inheriting from Merb::Controller instead of loaded statically on app load? I think that might fix both concerns and make it really act more like people might expect in the long run.
-
Michael Klishin (antares) August 2nd, 2008 @ 03:48 PM
- → Milestone changed from 0.9.4 to 1.0
- → Tag changed from to medium merb
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
