#5
Nov 27, 2008

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?在这个视频里将告诉你怎么做。

Bittorrent 种子下载 推荐使用 (10.4 MB, 6:14)
直接下载/Direct Download Link (10.4 MB, 6:14)

# 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

添加留言:/Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(可以使用pastie或者gist添加代码) (use pastie or gist for code)

if you want to help:
required:
BT下载工具
Get Bittorrent Tool
VLC播放器
Get VLC Media Player