Re: [Rails] Re: Helper to generate css-id from AR model. Do I have alzheimers?

2010-11-27 Thread David Kahn
On Fri, Nov 26, 2010 at 11:42 AM, Frederick Cheung frederick.che...@gmail.com wrote: On Nov 26, 4:13 pm, Rick DeNatale rick.denat...@gmail.com wrote: On one of the many Rails projects I've worked on over the years, I seem to recall using either a helper or a method on a model to

[Rails] Re: Helper to generate css-id from AR model. Do I have alzheimers?

2010-11-26 Thread Frederick Cheung
On Nov 26, 4:13 pm, Rick DeNatale rick.denat...@gmail.com wrote: On one of the many Rails projects I've worked on over the years, I seem to recall using either a helper or a method on a model to generate a css id based on the model class and id.  It was very useful particularly in making

Re: [Rails] Re: Helper to generate css-id from AR model. Do I have alzheimers?

2010-11-26 Thread Rick DeNatale
On Fri, Nov 26, 2010 at 12:42 PM, Frederick Cheung frederick.che...@gmail.com wrote: On Nov 26, 4:13 pm, Rick DeNatale rick.denat...@gmail.com wrote: On one of the many Rails projects I've worked on over the years, I seem to recall using either a helper or a method on a model to generate a

[Rails] Re: helper method does not include helper module into controller

2010-10-13 Thread Frederick Cheung
On 12 Oct, 17:24, Sophy ungso...@gmail.com wrote: Hi all, I want to include helper module into controller and I tried to use helper method but it doesn't work. It actually works in Rails 2.X. For instance, I have AppletsHelper and I want to include that module in my controller. So, in my

[Rails] Re: Helper in Initializer: Is it possible ?

2010-07-07 Thread Tom Ha
Thanks! -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to

[Rails] Re: Helper in Initializer: Is it possible ?

2010-07-06 Thread Marnen Laibow-Koser
Tom Ha wrote: Hi there, is there a way in Rails to use helpers in an Initializer ? You should never need to. Helpers are only for generating view code, and you shouldn't be doing that in initializers. If yes, how ? If no, where else to put the code needed in the Initializer (as well

[Rails] Re: Helper in Initializer: Is it possible ?

2010-07-06 Thread Tom Ha
What are you trying to achieve? Basically, I put some Rufus scheduler code in the Initializer folder so the scheduler runs fine, even when the hoster needs to reboot the machine for whatever reason and without my knowledge. The Rufus scheduler includes some .pdf-generating code (amongst other

[Rails] Re: Helper in Initializer: Is it possible ?

2010-07-06 Thread Bob Proulx
Tom Ha wrote: The .pdf must display numbers in a special format. And until now, I used helper code to get the numbers into this format, so it would have been convenient to use the same helper within this Rufus scheduler initializer.. To my casual eye this seems like something that should go

[Rails] Re: Helper in controller undefined when called

2009-11-12 Thread mvc
If you really want to use an existing Rails helper in your controllers, do the following : 1. add the following the following code to your application_controller (a singleton and a method): class Helper include Singleton include ActionView::Helpers::DateHelper include

[Rails] Re: Helper in controller undefined when called

2009-10-31 Thread Rick
Helper methods are used in the template class (ActionView::Template), not controllers. If I'm reading the documentation right, putting helper :all in a controller makes all helpers found in app/helpers/ **/*rb available in that controller's views. On Oct 31, 3:48 pm, Great John

[Rails] Re: helper for ajax field update

2009-07-22 Thread bill walton
Hi Bill, On Wed, 2009-07-22 at 14:09 -0700, billv wrote: I have a page that lists a set of tasks, each with a status field. I'd like the ability to update the status from this field, through a pop-up box. Basically, click the link, a little text area box opens, the user enters the update,

[Rails] Re: Helper for 2 controllers?

2009-04-23 Thread Maurício Linhares
Place it in a module somewhere and have both controllers to include that module. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Thu, Apr 23, 2009 at 4:47 PM, Heinz Strunk rails-mailing-l...@andreas-s.net wrote: Is there a DRY way to have a

[Rails] Re: Helper for 2 controllers?

2009-04-23 Thread Heinz Strunk
I included it in the controller with helper :points and called it like above but I get an error: undefined method create_points_account What could be the problem? Maurício Linhares wrote: Place it in a module somewhere and have both controllers to include that module. - Maur�cio

[Rails] Re: Helper for 2 controllers?

2009-04-23 Thread Maurício Linhares
I guess I did not made myself clear. I said create a module somewhere (usually under the lib folder), like: #lib/points.rb module Points def create_points_account( pts ) f = PointAccount.new(:points = pts) f.resource = self return false if !f.save end end And then at your

[Rails] Re: Helper for 2 controllers?

2009-04-23 Thread Heinz Strunk
I changed it from helper :fund to include Fund and it's included now but it doesn't really help cause there's still the error: undefined method `create_fund' for #User:0x5d52c6c -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this

[Rails] Re: Helper

2009-03-23 Thread anton effendi
add one def in application_helper.rb like : def show_flash(flash) html = if flash[:error] html += div class=error#{flash[:error]}/div end if flash[:warning] html + = div class=warning#{flash[:warning]}/div end if flash[:notice] html += div

[Rails] Re: Helper

2009-03-23 Thread Freddy Andersen
Or something like this: def flash_messages messages = [] %w(notice warning error).each do |msg| messages content_tag(:div, html_escape(flash [msg.to_sym]), :id = flash-#{msg}) unless flash[msg.to_sym].blank? end messages end %= flash_messages %

[Rails] Re: Helper

2009-03-23 Thread JL Smith
Another similar method... def show_flash [:notice, :warning, :message].collect do |key| content_tag(:div, flash[key], :class = flash_#{key}) unless flash[key].blank? end.join end --~--~-~--~~~---~--~~ You received this message because you are

[Rails] Re: Helper

2009-02-24 Thread Jo Jo
And same for option ? selected_option (value, content, x) if x = true then option value=value selected=selectedcontent/option else option value=valuecontent/option -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message

[Rails] Re: Helper

2009-02-24 Thread Frederick Cheung
On Feb 24, 8:04 am, Jo Jo rails-mailing-l...@andreas-s.net wrote: And same for option ? Come on, should be easy enough if you got the previous one :-) (not to mention that options_for_select etc. do this for you). Fred selected_option (value, content, x) if x = true then option

[Rails] Re: Helper

2009-02-24 Thread Jo Jo
Frederick Cheung wrote: Come on, should be easy enough if you got the previous one :-) Not for me :) I can't make it work: def current_option(value, content, x) selec = x ? selected : nil content_tag(:option, content, :value = value, :selected = selec) end -- Posted via

[Rails] Re: Helper

2009-02-20 Thread Andrew Bloom
Try something like this: def current_li(content, x) klass = x ? current : nil content_tag(:li, content, :class = klass) end On Feb 20, 3:55 pm, James Bond rails-mailing-l...@andreas-s.net wrote: How make a helper: If value X is true: print li class=current else li -- Posted

[Rails] Re: Helper

2009-02-20 Thread James Bond
Andrew Bloom wrote: def current_li(content, x) klass = x ? current : nil content_tag(:li, content, :class = klass) end Thanks, but why this doesn't work? %= current_li {link_to xxx, :controller = yyy}, @x == 1 % -- Posted via http://www.ruby-forum.com/.

[Rails] Re: Helper

2009-02-20 Thread Frederick Cheung
On Feb 20, 10:20 pm, James Bond rails-mailing-l...@andreas-s.net wrote: Andrew Bloom wrote: def current_li(content, x)   klass = x ? current : nil   content_tag(:li, content, :class = klass) end Thanks, but why this doesn't work? %= current_li {link_to xxx, :controller = yyy}, @x

[Rails] Re: helper for model?

2009-01-18 Thread Pardee, Roy
Abbott Sent: Friday, January 16, 2009 9:16 AM To: rubyonrails-talk@googlegroups.com Subject: [Rails] Re: helper for model? Yes. In your module you've defined an instance method not a class method. But this: class CarePhase ActiveRecord::Base include ModelHelper pretend_helper(hi

[Rails] Re: helper for model?

2009-01-16 Thread Pardee, Roy
-t...@googlegroups.com] On Behalf Of Joshua Abbott Sent: Wednesday, January 14, 2009 9:18 PM To: rubyonrails-talk@googlegroups.com Subject: [Rails] Re: helper for model? I just posted a similar question regarding best practices when you have methods you want to share across multiple AR models. I

[Rails] Re: helper for model?

2009-01-16 Thread Joshua Abbott
Yes. In your module you've defined an instance method not a class method. But this: class CarePhase ActiveRecord::Base include ModelHelper pretend_helper(hi!) Is the class trying to call the method, which fails because the class doesn't know about the 'pretend_helper' method.

[Rails] Re: helper for model?

2009-01-15 Thread Ar Chron
Another option is to inject an abstract class model between AR and the rest of your models. some class GenericModel ActiveRecord where GenericModel implements all manner of standard infrastructure functionality that is written once. Very easy for a specific model to override default

[Rails] Re: helper for model?

2009-01-14 Thread Brandon Keepers
On Wed, Jan 14, 2009 at 8:26 PM, Pardee, Roy parde...@ghc.org wrote: Hey All, I find I'm writing a ton of nearly identical model methods to support mass creation/update of child objects (a la the 'complex forms' series of railscasts). Stuff like: def

[Rails] Re: helper for model?

2009-01-14 Thread Joshua Abbott
I just posted a similar question regarding best practices when you have methods you want to share across multiple AR models. I ended up writing a module and sticking it in the lib directory. In order to make these methods available to your models, simply include it with: class Post

[Rails] Re: Helper methods not availlable in controller

2008-12-27 Thread Fernando Perez
Helper means view helper: they are only included in views. If you want a method you can call from views or controllers you need to define it in your controller (if you need all controllers to see it then in ApplicationController) and use helper_method to make it accessible to views. Fred

[Rails] Re: Helper methods not availlable in controller

2008-12-27 Thread Fernando Perez
Okay, so how would you allow a controller (or even a model) to use for instance the helpers truncate or sanitize? The solution I have found was to use xss_terminate plugin (compatible with Rails 2.2.2), it also allows to dive into its code and see how it is coded. -- Posted via

[Rails] Re: Helper methods from controller

2008-10-06 Thread Jon Stenqvist
Robby Russell wrote: On Sun, Oct 5, 2008 at 5:38 AM, Jon Stenqvist [EMAIL PROTECTED] wrote: Maybe Im not understanding your situation, but filters are more used for application logic and typical cases like logging, benchmarking etc. Wouldnt it be better to use the layouts folder and stick

[Rails] Re: Helper methods from controller

2008-10-05 Thread Raja Venkataraman
Jon Stenqvist wrote: Hi, I'm not sure i'm my design is correct, but i have around_filter in the controller, where i want to add a small javascript at the end of the page. Is there someway i can use the javascript_tag from the controller? i though there where a helpers proxy available.

[Rails] Re: Helper methods from controller

2008-10-05 Thread Jon Stenqvist
Raja Venkataraman wrote: Jon Stenqvist wrote: Hi, I'm not sure i'm my design is correct, but i have around_filter in the controller, where i want to add a small javascript at the end of the page. Is there someway i can use the javascript_tag from the controller? i though there where a

[Rails] Re: Helper methods from controller

2008-10-05 Thread Robby Russell
On Sun, Oct 5, 2008 at 5:38 AM, Jon Stenqvist [EMAIL PROTECTED] wrote: Raja Venkataraman wrote: Jon Stenqvist wrote: Hi, I'm not sure i'm my design is correct, but i have around_filter in the controller, where i want to add a small javascript at the end of the page. Is there someway i can

[Rails] Re: helper method problem

2008-09-28 Thread Jon Liu
class InventoryController ApplicationController def index @albums=Album.find(:all) @cart=find_cart end def add_to_cart itemType=params[:itemType] productId=(params[:id]) #parameter passed in from add to cart submission, it's either 1 or 2 in this

[Rails] Re: helper method problem

2008-09-27 Thread Phillip Koebbe
You'll want to put the shared method in app/controllers/application.rb Unless find_cart is used only in the one controller, then you just need to turn it into a before_filter: class MainController ApplicationController before_filter :set_cart def index end def what_ever