http://localhost:3000/ctrl/param_array?category[]=abc&category[]=test
class CtrlController < ApplicationController def param_array render :text => "categoryのパラメータ" + params[:category].inspect end end
categoryのパラメータ["abc", "test"]
http://localhost:3000/ctrl/param_array?category[param1]=abc&category[param2]=test
categoryのパラメータ{"param1"=>"abc", "param2"=>"test"}
http://localhost:3000/ctrl/param_array?category[param1][param1-1]=abc&category[param1][param1-2]=def&category[param2][param2-1]=test
categoryのパラメータ{"param1"=>{"param1-1"=>"abc", "param1-2"=>"def"}, "param2"=>{"param2-1"=>"test"}}
| query_parameters | GET→なんでget_parametersじゃないんだろ? |
| request_parameters | POST |
| path_parameters | ルートパラメータ |
def query_params render :text => "categoryのパラメータ" + request.query_parameters[:category].inspect end
http://localhost:3000/ctrl/query_params?category[param1]=abc&category[param2]=test
categoryのパラメータ{"param1"=>"abc", "param2"=>"test"}
def request_agent render :text => "User-Agent:" + request.headers['User-Agent'] end
User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
| メソッド名 | 概要 | 戻り値 |
| accept | クライアントがサポートしてるコンテンツの種類 | text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 |
| authorization | 認証情報 | |
| body | 生のポストデータ | # |
| content_length | コンテンツのサイズ | 0 |
| fullpath | リクエストのURL | /ctrl/request_methods?param1=val1 |
| get? | HTTP GETか? | true |
| post? | POSTか?(put/delete/headもあり) | false |
| host | ホスト名 | localhost |
| host_with_port | ポート付きのホスト名 | localhost:3000 |
| local? | ローカル通信か? | true |
| method | HTTPメソッド | GET |
| port | ポート番号 | 3000 |
| port_string | ポート番号の文字列 | :3000 |
| protocol | プロトコル | http:// |
| remote_ip | クライアントのIP | 127.0.0.1 |
| request_method | RailsのHTTPメソッド | GET |
| scheme | スキーマ名 | http |
| server_software | サーバのソフトウェア | webrick |
| ssl? | SSLか? | false |
| standard_port? | Well-knownポートであるか? | false |
| url | 完全なURL | http://localhost:3000/ctrl/request_methods?param1=val1 |
| xml_http_request? | XmlHttpRequestオブジェクトであるか? |
<%= form_tag( { :action => "upload_process" }, :multipart => true) do %>
<label>ファイルを指定:<%= file_field_tag "upfile" , { :size => 50 } %></label>
<%= submit_tag "アップロード" %>
<% end %>
def upload_process
file = params[:upfile]
File.open("public/docs/test.txt","wb") { |f| f.write(file.read) }
render :text => "アップロードしました"
end
def upload_process
file = params[:upfile]
name = file.original_filename
perms = ['.jpg','.jpeg','.gif','.png']
if !perms.include?(File.extname(name).downcase)
result = "アップロードできるのは画像ファイルだけです"
elsif file.size > 1.megabyte
result = "ファイルサイズは1Mバイトまでです"
else
File.open("public/docs/#{name}","wb") { |f| f.write(file.read) }
result = "#{name}をアップロードしました"
end
render :text => result
end
| original_filename | ファイル名 |
| content_type | コンテンツタイプ |
| size | ファイルサイズ |
| read | ファイルの内容の取得 |