0
通常,當我做一個POST或Web應用程序獲取HTTP調用,哈希,請直接從params哈希表:參數無法通過PARAMS哈希
@user = User.find(params[:id])
不過,我已經派內容類型「應用/ JSON」從Android應用,像這樣:
JSONObject holder = new JSONObject();
JSONObject userObj = new JSONObject();
userObj.put("username", params.get("name"));
userObj.put("uid", params.get("uid"));
userObj.put("image", params.get("image"));
userObj.put("provider", params.get("provider"));
holder.put("user", userObj);
query = holder.toString();
url = new URL("http://10.0.2.2:3001/users/auth/facebook/callback.json ");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setReadTimeout(10000);
urlConnection.setConnectTimeout(15000);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
OutputStream os = urlConnection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
當我看着日誌,是很好的被格式化的數據:
Processing by OmniauthCallbacksController#facebook as JSON
Parameters: {"user"=>{"username"=>"John Dough", "uid"=>"11111222444", ...
但是,我無法訪問params哈希表像這樣:
params_user # => nil
def params_user
params[:user].permit!
end
爲什麼我不能訪問params哈希表時,它顯然是可用?
如果我嘗試訪問它是這樣的:
params.parameters['user']
它告訴我則params的參數的方法是受保護的。但這是我使用調試器時唯一看到數據的地方。
NoMethodError (protected method `parameters' called for #<ActionController::Parameters:0x007fc51d1f9e08>):
是它阻止,因爲強大的參數? – emaillenin
@emaillenin沒有看到我的代碼:params [:user] .permit!我允許強參數 – Donato