隐藏字段标签值
从views/plans/new.html.erb
我得到的plan_id的数据类型和价格PARAMS下列要求:隐藏字段标签值
<%= link_to "Sign up", new_store_registration_path(:plan_id => plan.id, :price => plan.price) %>
然后应用重定向到注册页面,并与方法def after_inactive_sign_up_path_for(resource)
和def after_sign_up_path_for(resource)
我把以前的PARAMS并合并电子邮件PARAM:
registrations_controller.rb
class Stores::RegistrationsController < Devise::RegistrationsController
before_action :configure_permitted_parameters, if: :devise_controller?
def new
build_resource({})
resource.build_account
respond_with self.resource
session[:registration_params] = request.query_parameters
end
def create
build_resource(sign_up_params)
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
flash[:notice] = 'Successfully signed up'
respond_with resource, location: after_sign_up_path_for(resource)
else
flash[:notice] = "Signed up but #{resource.inactive_message}"
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end
def edit
super
end
def update
super
end
def destroy
super
end
def cancel
super
end
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) { |u|
u.permit(:email, :password, :password_confirmation, :remember_me,
:account_attributes => [:first_name, :last_name, :buisness_name,
:buisness_description, :web_site, :phone_number,
:street, :city, :state, :zip_code, :country])
}
end
def after_sign_up_path_for(resource)
new_transaction_path(resource, session[:registration_params].merge(email: resource.email))
end
def after_inactive_sign_up_path_for(resource)
new_transaction_path(resource, session[:registration_params].merge(email: resource.email))
end
end
提交申请之后,应用程序红色向具有plan_id
,price
和email
参数的views/transcation/new.html.erb发送。
Parameters: {"email"=>"[email protected]", "plan_id"=>"bs96", "price"=>"150.0"}
和URL显示:
http://localhost:3000/transactions/new.1?ema%E2%80%8C%E2%80%8Bil=example%40gmail.com&plan_id=bs96&price=150.0
内部的意见/ transcation/new.html.erb存在UI的布伦特里下降,并与三个隐藏字段一起脚本:
<div class="form-container radius-box glassy-bg small-10 small-centered medium-8 large-6 columns">
<%= form_tag transactions_path do%>
<div id="dropin"></div>
<%= hidden_field_tag(:email, params["email"]) %>
<%= hidden_field_tag(:plan_id, params["plan_id"]) %>
<%= hidden_field_tag(:amount, params["price"]) %>
<%=submit_tag "Pay #{params["price"]}$", class: "button mt1" %>
<%end%>
</div>
<script>
braintree.setup("<%[email protected]_token%>", 'dropin', {
container: 'dropin'
});
</script>
在这一点上,我试图将电子邮件PARAM保持到交易与<%= hidden_field_tag(:email, params["email"]) %>
但如果我点击提交我没有收到一封电子邮件,你可以看到如下内容:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"KeS2xK7NIJZwFQvW2kJKupcpURnQweq+yoRgk9AJ1aaOgFIIym4RKadI4jc6vYynMo4vKR4eLmdIynfBG+EusQ==", "email"=>"", "plan_id"=>"bs96", "amount"=>"150.0", "payment_method_nonce"=>"0c22f2fa-e212-0ad3-753b-0d183d02522b"}
如果我考察的意见/ transcation/new.html.erb内PARAMS这个<%= params.inspect %>
它打印出这个:<ActionController::Parameters {"email"=>"[email protected]", "plan_id"=>"bs96", "price"=>"150.0", "controller"=>"transactions", "action"=>"new"} permitted: false>
这<%= params[:email].inspect %>
回报nil
任何想法,为什么我不能得到电子邮件PARAM?
是这个问题相同https://stackoverflow.com/questions/45568785/pass-hidden-field-tag-params-with-rails-5 – MZaragoza
如果您在表单中打印PARAMS [“email”]有没有什么价值? – Anton
感谢您的回复@Anton ...''this returns nil ...但是这个''将电子邮件和所有其他params – Theopap