I'm new for rails and ruby. I try to make a simple project and have this problem. I have a view with some text fields on it, when I press submit button, in my controller I need the values from this fields as strings, I try this way params[:field1]
, but the value is in this format {"field1"=>"some_value"}, it's not a string and I have the problems with it. How can I solve it?
UP: view code
<%= form_tag :action=>:login_user do %>
<div class="field">
<h2>Login</h2>
<%= text_field "field1", "field1" %>
</div>
<div class="field">
<h2>Password</h2>
<%= password_field "field2", "field2" %>
</div>
<div class="actions">
<%= submit_tag "Login" %>
</div>
<% end %>
params[:field1]
is correct way.
Your params is a hash:
params => {"field1"=>"some_value"}
so to get field1
you should call params[:field1]
UPD
For your structure (that is actaully bad) you should call for params this way:
params[:field1][:field1]
params[:field2][:field2]
better to use text_field_tag
and password_field_tag
in your case:
<%= text_field_tag :field1 %>
<%= password_field_tag :field2 %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With