I need to know how you could make a form where you can select a record, do some calculations based on that record and display the results (preferably on the same page).
To make it as simple as possible let's say I want to select a record from the User model and show his capitalized email.
So the structure would be:
capitalized_controller.rb
class CapitalizedController < ApplicationController
before_action :authenticate_user!
def users
@users = User.all
end
end
capitalized/users.html.erb:
<%= form_tag('/capitalized/users') do %>
<div class="controls">
<%= select_tag :email, options_from_collection_for_select(@users, "id", "email"), :class => 'text_field' %>
</div>
<div class="form-actions">
<%= submit_tag nil, :class => 'btn btn-primary' %>
</div>
<% end %>
And it's being displayed like this:
So, until here it shows me a list of the user's emails sorted alphabetically and I can hit the send button ("Enviar") and it works perfect (I have no errors so far), but it only load the page again, what should I do to show the capitalized email?
Aucun commentaire:
Enregistrer un commentaire