Button with a value - Ruby on Rails

2

I have 2 buttons and each one will have to send a value of the model and will also be submit

button 1 and button 2 - depending on the button I click it will send the value to the field @ evaluation.type. Similar to a like and dislike . The possible code I imagine should be in view in helper form_for

[button 1]:

<%= form_for(@avaliacao) do |f| %>
    <%= render 'compartilhado/mensagens_erro', object: f.object %>
    <%= f.hidden_field :item_id %>
    <div class="field">
      <%= f.text_area :avaliacao, placeholder: "Escreva seu Comentario..." %>
    </div>
<!-- Seria isso no f.submit?? -->
    <div class="col-md-4.5 col-md-offset-8">
      <%= f.submit "Avaliar!", class: "btn btn-large btn-primary" %
    </div>
<% end %>
    
asked by anonymous 08.05.2014 / 04:40

1 answer

0

Try the following (did not test in practice):

Create the @avaliação.tipo field of type hidden :

<%= f.hidden :tipo, id: 'hidden_tipo' %>

Make the submit invisible:

<%= f.submit "Avaliar!", class: "..." style='display: none' id='submit' %>

Create the two buttons and use jQuery to change the hidden field and submit the form:

$('#botao1').click(function() {
  $('#hidden_tipo').val('like');
  $('#submit').click();
});
    
08.05.2014 / 13:37