åºå«æ¯ï¼
renderä¸ä¼å»æ§è¡controllerä¸çactionæ¹æ³ï¼ç´æ¥æ¸²æç¸åºç页é¢æ件ï¼å¯ä»¥ä½¿ç¨çãåæ°å¦ä¸ï¼
[ruby] view plain copy
render(:text => string)
render(:inline => string, [:type => "rhtml"|"rxml"])
render(:action => action_name)
render(:file => path, [:use_full_path => true|false])
render(:template => name)
render(:partial => name)
render(:nothing=>true)
render()
第1è¡ï¼ç´æ¥æ¸²æåºææ¬
第2è¡ï¼æä¼ å
¥çstring渲ææ模æ¿ï¼rhtmlæè
rxmlï¼
第3è¡ï¼ç´æ¥è°ç¨æ个actionç模æ¿ï¼ç¸å½äºforwardå°ä¸ä¸ªview
第4è¡ï¼ä½¿ç¨æ个模æ¿æ件render, å½use_full_pathåæ°ä¸ºtrueæ¶å¯ä»¥ä¼ å
¥ç¸å¯¹è·¯å¾
第5è¡ï¼ä½¿ç¨æ¨¡æ¿årenderï¼e.x.: render(:template => "blog/short_list")
第6è¡ï¼ä»¥å±é¨æ¨¡æ¿æ¸²æ
第7è¡ï¼ä»ä¹ä¹ä¸è¾åº,å
æ¬layout
第8è¡ï¼é»è®¤ççrender, ç¸å½äºrender(:action => self)
Redirectæ¯è·³è½¬å°ä¸ä¸ªæ°çactionä¸ç»§ç»æ§è¡ï¼ç¸å½äºæµè§å¨åéäºä¸ä¸ªæ°ç请æ±ï¼å¹¶ä¸é»è®¤è¿å302ç¶æç ãä¾å¦ï¼
[ruby] view plain copy
def redirect_to(options = {}, response_status = {}) #:doc:
raise ActionControllerError.new("Cannot redirect to nil!") if options.nil?
if options.is_a?(Hash) && options[:status]
status = options.delete(:status)
elsif response_status[:status]
status = response_status[:status]
else
status = 302
end
response.redirected_to = options
case options
# The scheme name consist of a letter followed by any combination of
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
# characters; and is terminated by a colon (":").
when %r{^\w[\w\d+.-]*:.*}
redirect_to_full_url(options, status)
when String
redirect_to_full_url(request.protocol + request.host_with_port + options, status)
when :back
if referer = request.headers["Referer"]
redirect_to(referer, :status=>status)
else
raise RedirectBackError
end
else
redirect_to_full_url(url_for(options), status)
end
end
温馨提示:答案为网友推荐,仅供参考