Dynamic Namespaced Paths

30 views
Skip to first unread message

Steven Garcia

unread,
Sep 3, 2010, 8:56:32 AM9/3/10
to pickle
I have "/post/1" and I also have "admin/post/1"

I can currently say: "Then I should be on the post's page" and it
works fine.

But throw a controller namespace in there and it all goes haywire. So
after getting tired of defining each of my admin paths manually, I
decided to do a little tinkering inside paths.rb:

when /admin #{capture_model}(?:'s)? page/
path_to_pickle "admin", $1

In theory that should work, but in practice I get:

Could not figure out a path for ["admin", "post"] {} (RuntimeError)
./features/support/paths.rb:16:in `path_to'
./features/step_definitions/web_steps.rb:203:in `/^(?:|I )should be on
(.+)$/'
features/manage_newsfeeds.feature:12:in `Then I should be on the admin
post's page'

Any idea where I went wrong here? I certainly dont want to go back to
manual paths for each and every resource/action.

Ian White

unread,
Sep 3, 2010, 9:22:18 AM9/3/10
to pickle-...@googlegroups.com
Hi Steven,

path_to_pickle does need a bit of love. I wrote it as a bit of an experiment.

Until it gets som elove, In your case, I would suggest using rails helpers + pickle to achieve the outcome (take path_to_pickle out of the loop)

something like:

when /admin #{capture_model}(?:'s)? page/

polymorphic_path [:admin, model!($1)]


Cheers,
Ian

> --
> You received this message because you are subscribed to the Google Groups "pickle" group.
> To post to this group, send email to pickle-...@googlegroups.com.
> To unsubscribe from this group, send email to pickle-cucumb...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pickle-cucumber?hl=en.
>

Steven Garcia

unread,
Sep 3, 2010, 9:28:01 AM9/3/10
to pickle
Thanks for the prompt reply Ian

That did the trick quite nicely. I've even set it up to work with
different namespaces like so:

when /the (.+?) #{capture_model}(?:'s)? page/
polymorphic_path [$1.to_sym, model!($2)]

Really quite happy with this solution for now, but maybe in the future
path_to_pickle should accept option[:namespace] ?

Steven Garcia

unread,
Sep 3, 2010, 9:43:14 AM9/3/10
to pickle
For anyone else trying this and wondering how to get the edit/index
paths to behave, just slap this in your paths.rb:

when /the (.+?) #{capture_model}(?:'s)? page/
polymorphic_path [$1.to_sym, model!($2)]

when /the (.+?) #{capture_model}(?:'s)? (.+?) page/
polymorphic_path [$3.to_sym, $1.to_sym, model!($2)]

when /the (.+?) (.+?) listing page/
polymorphic_path [$1.to_sym, $2.to_sym]

Now you can say

Then I should be on the admin post's page
Then I should be on the admin post's edit page
Then I should be on the admin posts listing page

That should cover you till path_to_pickle gets the love it needs

Ian White

unread,
Sep 3, 2010, 9:47:32 AM9/3/10
to pickle-...@googlegroups.com
Hi Steve,

That works nicely.

> Really quite happy with this solution for now, but maybe in the future
> path_to_pickle should accept option[:namespace] ?

I plan to have path_to_pickle take a splat, if any of the args are symbols then they're just plonked into the polymorphic_path in place,
if they're strings, they are treated as pickle refs

Cheers,
Ian

Steven Garcia

unread,
Sep 3, 2010, 12:24:43 PM9/3/10
to pickle
Sounds good Ian, looking forward to it

Sachin Sagar Rai

unread,
Sep 3, 2010, 2:49:50 PM9/3/10
to pickle-...@googlegroups.com
yes, thats cool.
Before, I too had concerns. Tried couple of times, but couldn't figure out.
I really got to try this out.

+1 in the name of love.

Sachin Sagar Rai (aka - millisami)
Freelance Ruby on Rails Web Developer
http://www.tfm.com.np
http://www.welcometonewnepal.com
9803857018


On Fri, Sep 3, 2010 at 10:09 PM, Steven Garcia <steven...@gmail.com> wrote:
Sounds good Ian, looking forward to it
Reply all
Reply to author
Forward
0 new messages