#5
Nov 27, 2008
0 comments
Helpers Outside Views- 视图外的helper
Have you ever wanted to access helper methods outside of the view layer? In this episode I show you a couple ways to do just that.
你是否想在视图外访问helper mothods?在这个视频里将告诉你怎么做。
# models/category.rb def description "This category has #{helpers.pluralize(products.count, 'product')}." end def helpers ActionController::Base.helpers end # products_controller.rb def create @product = Product.new(params[:product]) if @product.save flash[:notice] = "Successfully created #{@template.link_to('product', @product)}." redirect_to products_url else render :action => 'new' end end

