From: David Pollak Date: 2006-06-25T23:15:04+09:00 Subject: Re: Help with "generating" code ------=_Part_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 = Channel.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 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 = Channel.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 ------=_Part_36121_19506963.1151244900665--