In your controller action you can do this:
class WhitelabelsController < ActionController
def edit
@whitelabel = params[:id] ? Whitelabel.find(params[:id]) : current_whitelabel
redirect_to whitelabels_url unless @whitelabel
....
end
...
end
Now rails will treat /whitelabel/edit
as /whitelabel/edit/#{current_whitelabel.id}
without specifying the id.
If this happens for more than one action you can do it as a before filter. Just be sure to remove all @whitelabel = Whitelable.find(params[:id])
lines from the individual actions.
class WhitelabelsController < ActionController
before_filter :select_whitelabel, :except => [:index, :new]
def select_whitelabel
@whitelabel = params[:id] ? Whitelabel.find(params[:id]) : current_whitelabel
redirect_to whitelabels_url unless @whitelabel
end
...
end
Answering the more clearly stated question in the comment:
You can use a singular resource in tandem with the above code to have the effect you want.
config/routes.rb
map.resource :my_whitelabel, :controller => "whitelabels", :member => {:dashboard => :get}
Then in the whitelabels controller use the above code. This keeps things DRY by using the same controller for different paths with the same actions. The resource defines a dashboard action, so you'll have to add that to the controller too. But if you're using the before_filter version there should be no problem.