Reputation: 755
From theviews/plans/new.html.erb
I get the plan_id and price params with the following:
<%= link_to "Sign up", new_store_registration_path(:plan_id => plan.id, :price => plan.price) %>
Then the app redirects to the sign-up page and with the following I keep the previous params and add the email as well:
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
Finally after sign-up, the app redirects to the views/transcation/new.html.erb, which has the plan_id
, price
and email
params.
Parameters: {"email"=>"[email protected]", "plan_id"=>"bs96", "price"=>"150.0"}
At this point I'm trying to pass the email param to the transaction with <%= hidden_field_tag(:email, params["email"]) %>
But not getting an email as you can see in the following:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"KeS2xK7NIJZwFQvW2kJKupcpURnQweq+yoRgk9AJ1aaOgFIIym4RKadI4jc6vYynMo4vKR4eLmdIynfBG+EusQ==", "email"=>"", "plan_id"=>"bs96", "amount"=>"150.0", "payment_method_nonce"=>"0c22f2fa-e212-0ad3-753b-0d183d02522b"}
Any ideas on what I'm doing wrong???
Update1
Inside the views/transcation/new.html.erb there is the braintree drop in ui and the script along with the three hidden fields:
<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>
Upvotes: 1
Views: 9538
Reputation: 192
There are Two tags for add Hidden fields in ruby on rails view
Form for rails view with hidden fields
<% 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>
<% end %>`
Controller code:
params[:selected]="column_name"
params[:request][:column_name] = request.column_name
When we used f.hidden_field:
<%= f.hidden_field :column_name %>
it change to html:
<input type="hidden" id="request_column_name" name="request[column_name]" value="#{@request.column_name}" />
and when we used hidden_field_tag
<%= hidden_field_tag 'selected', 'column_name' %>
it change to html:
<input id="selected" name="selected" type="hidden" value="none"/>
And we can send a custom value as a hidden input for your model like that:
<%= f.hidden_field :model_field_name, value: 12 %>
Upvotes: 0
Reputation: 3790
I hope you have not confused.
<%= hidden_field_tag "email", params[:email] %>
hidden_field_tag
used with form_tag
<%= f.hidden_field "email", params[:email] %>
and f.hidden_field
is used with form_for
Upvotes: 3
Reputation: 192
Please set the value of hidden field like:
<%= f.hidden_field :email, :value => "[email protected]" %>
or
<%= f.hidden_field :email, :value => @object.email %>
Upvotes: 5