This is likely something easy to accomplish, but I'm having difficulty even articulating clearly, leading me to get all sorts of semi-germaine, but not quite what I'm after posts on SO when searching.
I have a resource, we'll just use User as a simple to discuss use case. I desire SEO friendly URLs, so instead of ~/users/:id, we have ~/users/:name, where the show action on my users controllers is doing a User.find_by_name(:name). Works great.
In various parts of the app, I want to redirect the end user back to my resource. The docs seem to indicate I should do
redirect_to @user, :notice => "your page is now DIAMONDS!"'
The problem here is that this automatically appears to use the :id value of the resource, which isn't what I'm after. I'm wondering if there's a way to just define a route in my routes file which is aware of my desire to use the name property--and then just redirect to the generated route_url helper. But I'm at a loss for how to do that.
In the interim, I'm resorting to this:
flash[:notice] = "Your account is now DIAMONDS. *fist bump*"
redirect_to :action => :show , :id => @user.name
This is less than ideal to me as it's a good bit of repeated code (I have lots of UI elements that will be linking back to my resource) and because I can't seem to figure out how to include the flash as part of the redirect_to method call---every combo of curly bracing w/in the redirect_to that includes a flash bombs on me.
I don't think it's germaine to my problem specifically, but I am doing this on Rails 3 in case it does have some implication in terms of options available to me.
Sorry for the noobishness :)