Hi everyone :-) If I wanted to make an RJS template generate something, how would I go about doing that? Like, right now you have page.insert_html, etc., but let''s say I wanted to define my_page.insert_html, and I want it to generate different code. How would I do that? Thanks! Sean -- View this message in context: http://www.nabble.com/RJS%3A-how-to-generate-different-code---plugins--tf2941465.html#a8224678 Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
duma wrote:> Hi everyone :-) > > If I wanted to make an RJS template generate something, how would I go > about > doing that? Like, right now you have page.insert_html, etc., but let''s > say > I wanted to define my_page.insert_html, and I want it to generate > different > code. How would I do that? > > Thanks! > Sean > -- > View this message in context: > http://www.nabble.com/RJS%3A-how-to-generate-different-code---plugins--tf2941465.html#a8224678 > Sent from the RubyOnRails Users mailing list archive at Nabble.com.It seems that that page object is a: ActionView::Helpers::PrototypeHelper::JavaScriptGenerator So you should be able to extend that. I just tested this out and it seems to work fine. class ActionView::Helpers::PrototypeHelper::JavaScriptGenerator def foo(m) call "alert", m #same as: call "alert(''#{m}'')" end end then you can do: render(:update) { |page| page.foo(''Foo!'') } #=> "alert(''foo'')" If you want to override one the original methods, you can use alias_method_chain. class ActionView::Helpers::PrototypeHelper::JavaScriptGenerator def alert_with_foo(message) alert_without_foo("#{message} Foo!") end alias_method_chain :alert, :foo end render(:update) { |page| page.alert(''Hi'') } #=> "alert(''Hi Foo!'')" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nice!! Thank you so much!! :-) Paul Johnson-18 wrote:> > > duma wrote: >> Hi everyone :-) >> >> If I wanted to make an RJS template generate something, how would I go >> about >> doing that? Like, right now you have page.insert_html, etc., but let''s >> say >> I wanted to define my_page.insert_html, and I want it to generate >> different >> code. How would I do that? >> >> Thanks! >> Sean >> -- >> View this message in context: >> http://www.nabble.com/RJS%3A-how-to-generate-different-code---plugins--tf2941465.html#a8224678 >> Sent from the RubyOnRails Users mailing list archive at Nabble.com. > > It seems that that page object is a: > > ActionView::Helpers::PrototypeHelper::JavaScriptGenerator > > So you should be able to extend that. I just tested this out and it > seems to work fine. > > class ActionView::Helpers::PrototypeHelper::JavaScriptGenerator > def foo(m) > call "alert", m > #same as: call "alert(''#{m}'')" > end > end > > then you can do: > > render(:update) { |page| page.foo(''Foo!'') } > #=> "alert(''foo'')" > > If you want to override one the original methods, you can use > alias_method_chain. > > class ActionView::Helpers::PrototypeHelper::JavaScriptGenerator > def alert_with_foo(message) > alert_without_foo("#{message} Foo!") > end > alias_method_chain :alert, :foo > end > > render(:update) { |page| page.alert(''Hi'') } > #=> "alert(''Hi Foo!'')" > > -- > Posted via http://www.ruby-forum.com/. > > > > >-- View this message in context: http://www.nabble.com/RJS%3A-how-to-generate-different-code---plugins--tf2941465.html#a8230019 Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---