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