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
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
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
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
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
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
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
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
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
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
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,
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
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
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
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
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
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 %
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
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
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
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
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
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/.
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
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
-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
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.
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
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
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
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
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
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
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.
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
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
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
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
38 matches
Mail list logo