在查询字符串中添加参数Rails

时间:2017-08-09 11:56:58

标签: ruby-on-rails ruby ruby-on-rails-4 devise

我将查询字符串中的参数添加到new_store_registration的路径中,并由after_sign_up_path_for方法保存。 registrations_controller.rb

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


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

我拉下了以下的参数:

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

注册后,该应用会重定向到views / transcation / new.html.erb,其中包含plan_id,price params。

此时我正试图在new.html.erb中传递电子邮件参数并保留其余的参数:

<%= 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"=>"example@gmail.com", "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", "example@gmail.com"], ["LIMIT",  1]]
  SQL (0.5ms)  INSERT INTO "stores" ("email", "encrypted_password",  "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["email",  "example@gmail.com"], ["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"=>"example@gmail.com", "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 个答案:

答案 0 :(得分: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

仔细检查&amp;重新键入email,您可以在其中进行设置。