ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2010年3月3日 星期三
respond_to
#===============================================
class ApplicationController < ActionController::Base
before_filter :adjust_format_for_iphone
helper_method :iphone_user_agent?
protected
def adjust_format_for_iphone
request.format = :iphone if iphone_user_agent? || iphone_subdomain?
end
# Request from an iPhone or iPod touch?
# (Mobile Safari user agent)
def iphone_user_agent?
request.env["HTTP_USER_AGENT" ] &&
request.env["HTTP_USER_AGENT" ][/(Mobile\/.+Safari)/]
end
def iphone_subdomain?
return request.subdomains.first == "iphone"
end
end
# =======================
# custom format
# config/initializers/mime_types.rb
Mime::Type.register ‘audio/mpeg’, :mp3?Mime::Type.register ‘audio/mpegurl’, :m3u
def show
@mp3 = Mp3.find(params[:id])
respond_to do |format|
format.html
format.mp3 { redirect_to @mp3.url }
format.m3u { render :text => @mp3.url }
end
end
#========================
def index
@users = User.find(:all)
respond_to do |format|
format.js {
render :update do |page|
page.replace_html ‘content’, ‘
blah
’
end
}
format.html #index.html.erb
end
end
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言