从views/plans/new.html.erb
我得到了plan_id和price params,内容如下:
<%= link_to "Sign up", new_store_registration_path(:plan_id => plan.id, :price => plan.price) %>
然后,应用程序重定向到注册页面,然后我保留以前的参数并添加电子邮件:
registrations_controller.rb
def after_sign_up_path_for(resource)
new_transaction_path(session[:registration_params].merge(email: resource.email))
end
def after_inactive_sign_up_path_for(resource)
new_transaction_path(session[:registration_params].merge(email: resource.email))
end
最后,在注册后,该应用会重定向到views / transcation / new.html.erb,其中包含plan_id
,price
和email
参数。
Parameters: {"email"=>"example@gmail.com", "plan_id"=>"bs96", "price"=>"150.0"}
此时我试图通过<%= 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"}
关于我做错的任何想法???
UPDATE1
在views / transcation / new.html.erb中,ui中有braintree drop,脚本连同三个隐藏字段:
<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("<%=@client_token%>", 'dropin', {
container: 'dropin'
});
</script>
答案 0 :(得分:1)
请设置隐藏字段的值,如:
<%= f.hidden_field :email, :value => "test@test.com" %>
或
<%= f.hidden_field :email, :value => @object.email %>
答案 1 :(得分:0)
我希望你没有混淆。
<%= hidden_field_tag "email", params[:email] %>
hidden_field_tag
与form_tag
<%= f.hidden_field "email", params[:email] %>
只有f.hidden_field
与form_for
答案 2 :(得分:0)
在 ruby on rails 视图中有两个用于添加隐藏字段的标签
<块引用>带有隐藏字段的 rails 视图表单
<% form_for(:request, :url => requests_path) do |f| %>
`<div class="actions">`
<%= f.hidden_field :column_name %>
<%= hidden_field_tag 'selected', 'column_name' %>
<%= f.submit e %>
</div>
<% 结束 %>`
<块引用>控制器代码:
params[:selected]="column_name"
params[:request][:column_name] = request.column_name
<块引用>
当我们使用 f.hidden_field 时:
<%= f.hidden_field :column_name %>
<块引用>
它更改为 html:
<input type="hidden" id="request_column_name" name="request[column_name]" value="#{@request.column_name}" />
<块引用>
当我们使用 hidden_field_tag
<%= hidden_field_tag 'selected', 'column_name' %>
<块引用>
它更改为 html:
<input id="selected" name="selected" type="hidden" value="none"/>
<块引用>
我们可以像这样发送自定义值作为模型的隐藏输入:
<%= f.hidden_field :model_field_name, value: 12 %>