Hi! Thanks for the helpful answers.
I don’t know what really you want to do with :model_id => user.id
I have written a plugin that handles all the CRUD stuff that Rails’
scaffolds does. So instead of having index, list, show, new etc.
methods, I just can call performs_scaffolding which adds all the
required methods to the controller.
So far, it always used params[:id] to determine which instance to get
for edit, show, destroy etc.
But now I created a controller that represents the logged in user’s
(member) control panel:
class MemberController < ApplicationController
performs_scaffolding :only => [:show, :edit]
…
end
This controller doesn’t have a “param” part in the URL, because the
logged in user should work on his own “Member” model only (anything else
would be a hacking attempt):
map.member ‘member/:action’,
:controller => ‘member’
So at this time, there’s no params[:id] object when calling member/edit.
Because of this, performs_scaffolding needs another way on how to get an
ID from the programmer. So I added the optional key “model_id” to the
options hash:
performs_scaffolding :only => [:show, :edit],
:model_id => 1234
When this option is set, then performs_scaffolding doesn’t look for
params[:id] anymore but always uses the passed model ID.
So in my case, I want to pass always the ID of the logged in user which
is returned by the instance method “user”:
performs_scaffolding :only => [:show, :edit],
:model_id => user.id
So what to do now? Making the user method a class method? Or using the
Proc method? Or any better idea?
Thanks
Josh