ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2009年9月9日 星期三
Railscast skill (4)
Pretty Page Title
把content_for 弄簡潔了, yield 也要有default
# application_helper.rb
def title(page_title)
content_for(:title) { page_title }
end
<[title>Shoppery - <%= yield(:title) || "The Place to Buy Stuff" %>
Markaby in Helper
也可以在helper 裡用render :partial 或者是用content_tag 去拼view
# in helper
def simple_error_messages_for(object_name)
object = instance_variable_get("@#{object_name}")
return if object.errors.empty?
markaby do
div.error_messages! do
h2 "#{pluralize(object.errors.count, 'error')} occurred"
p "There were problems with the following fields:"
ul do
object.errors.each_full do |msg|
li msg
end
end
end
end
end
def markaby(&block)
Markaby::Builder.new({}, self, &block)
end
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言