2017-08-09 65 views
0

我將查詢字符串中的參數添加到new_store_registration並由after_sign_up_path_for方法保留的路徑中。 registrations_controller.rb在查詢字符串中添加參數Rails

def new 
    session[:registration_params] = request.query_parameters 
end 


def after_sign_up_path_for(resource) 
    new_transaction_path(resource, session[:registration_params]) 
end 

我拉着以下PARAMS:

<%= link_to "Sign up", new_store_registration_path(:plan_id => plan.id, :price => plan.price) %> 

申請成功後,應用程序重定向到的意見/ transcation/new.html.erb,它具有plan_id的數據類型,價格參數。

在這一點上我試圖通過new.html.erb內部電子郵件PARAM並保持休息PARAMS有:

<%= hidden_field_tag(:email, params[:email]) %> 
<%= hidden_field_tag(:plan_id, params["plan_id"]) %> 
<%= hidden_field_tag(:amount, params["price"]) %> 

但電子郵件參數是上來了空

Parameters: {"utf8"=>"✓", "authenticity_token"=>"KeS2xK7NIJZwFQvW2kJKupcpURnQweq+yoRgk9AJ1aaOgFIIym4RKadI4jc6vYynMo4vKR4eLmdIynfBG+EusQ==", "email"=>"", "plan_id"=>"bs96", "amount"=>"150.0", "payment_method_nonce"=>"0c22f2fa-e212-0ad3-753b-0d183d02522b"} 

任何想法,爲什麼這不工作???

UPDATE1

我提交申請成功後我得到這個:

Started POST "/stores" for 127.0.0.1 at 2017-08-09 15:24:17 +0300 
Processing by Stores::RegistrationsController#create as HTML 
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8szvzrbEVUb1xvYcKwidi+4AYnQD46R96Y0C6ONiI65mEtRkATtJ IRXCb60UNyKs0knwpeDnMLwy9iXmK8TRgw==", "store"=> {"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "account_attributes"=> {"first_name"=>"ted", "last_name"=>"tedpaps", "buisness_name"=>"1", "buisness_description"=>"1", "web_site"=>"1", "phone_number"=>"1", "street"=>"1", "city"=>"1", "state"=>"1", "zip_code"=>"1", "country"=>"1"}}, "commit"=>"Sign up"} 
    (0.1ms) begin transaction 
    Store Exists (0.2ms) SELECT 1 AS one FROM "stores" WHERE "stores"."email" = ? LIMIT ? [["email", "[email protected]"], ["LIMIT", 1]] 
    SQL (0.5ms) INSERT INTO "stores" ("email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["email", "[email protected]"], ["encrypted_password", "$2a$11$Xet14fY.N3rvvPZ2sjdn6ObbKShVMkw/4qmPWiPG/OjsRmiIxqlGq"], ["created_at", "2017-08-09 12:24:17.640427"], ["updated_at", "2017-08-09 12:24:17.640427"]] 
    SQL (0.2ms) INSERT INTO "accounts" ("buisness_name", "buisness_description", "web_site", "phone_number", "street", "zip_code", "country", "first_name", "last_name", "created_at", "updated_at", "store_id", "city", "state") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["buisness_name", "1"], ["buisness_description", "1"], ["web_site", "1"], ["phone_number", "1"], ["street", "1"], ["zip_code", "1"], ["country", "1"], ["first_name", "ted"], ["last_name", "tedpaps"], ["created_at", "2017-08-09 12:24:17.642495"], ["updated_at", "2017-08-09 12:24:17.642495"], ["store_id", 1], ["city", "1"], ["state", "1"]] 
    (1.6ms) commit transaction 
Redirected to http://localhost:3000/transactions/new.1?ema%E2%80%8C%E2%80%8Bil=example%40gmail.com&plan_id=bs96&price=150.0 
Completed 302 Found in 160ms (ActiveRecord: 2.6ms) 

並重定向到:

Started GET "/transactions/new.1?ema%E2%80%8C%E2%80%8Bil=example%40gmail.com&plan_id=bs96&price=150.0" for 127.0.0.1 at 2017-08-09 15:24:17 +0300 
Processing by TransactionsController#new as 
Parameters: {"ema‌​il"=>"[email protected]", "plan_id"=>"bs96", "price"=>"150.0"} 
Rendering transactions/new.html.erb within layouts/application 
Rendered transactions/new.html.erb within layouts/application (1.0ms) 
Completed 200 OK in 1209ms (Views: 37.7ms | ActiveRecord: 0.0ms) 

回答

1

看你的更新,似乎存在一個字符您的email參數名稱看起來像a但不是。它可以從

Started GET "/transactions/new.1?ema%E2%80%8C%E2%80%8Bil=example%40gmail.com&plan_id=bs96&price=150.0" for 127.0.0.1 at 2017-08-09 15:24:17 +0300 

仔細檢查,可以看出&重新輸入email你在哪裏設置它。

+0

不,仍然沒有工作! – Theopap

+0

@Theopap我更新了答案。 – vijoc

+0

嗯...我看不到'a'錯字,它在哪裏? – Theopap