------ art_36121_19506963.1151244900665
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Merc,
You could add a method to Channel that looks like:
class Channel
def self.standard_create(params, controller)
ret hannel.new params
if ret.save
controller.flash[:notice] Channel was saved'
controller.redirect_to :action 'index'
else
controller.render :action 'new'
end
return ret
end
end
No need for metaprogramming in this case, just a simple method.
Thanks,
David
On 6/24/06, Tony Mobily <merc / mobily.com> wrote:
>
> Hello,
>
> OK, this is a Ruby question, even though it's for a RoR project :-D
> I am a pretty hopeless Ruby programmer. I am getting better, but when
> it's about eval(), symbols and introspection, I still crumble...
> Besides, I am not even sure what I want to do is actually possible in
> Ruby.
>
> At one point, in my program I have this:
>
> def create
> @channel hannel.new(params[:channel])
> if @channel.save
> flash[:notice] Channel was successfully created.'
> redirect_to :action 'index'
> else
> render :action 'new'
> end
> end
>
> What I want to do, is being able to write:
>
> def create
> ApplicationController::standard_create(:channel)
> end
>
> That "standard_create" function should execute the code, but in
> create()'s scope.
> What I don't know is:
>
> 1) How to keep the code execute by
> ApplicationController::standard_create in create()'s scope
> 2) From ApplicationController::standard_create(name), what to do to
> "create the code"
>
> Any help would be _immensely_ appreciated!
>
> Thanks a lot,
>
> Merc.
>
> --
> Posted via http://www.ruby-forum.com/.
>
>
--
--------
David Pollak's Ruby Playground
http://dppruby.com
------ art_36121_19506963.1151244900665--