2

I am still learning Ruby on Rails and was trying to do call a custom method check_bike_in in that controller and passing it the values from the check box and text area when I click the button.

I am using the helper_method to call check_bike_in, but I am not sure how to call it when the button is clicked or how to pass the variables to the controller.

Any help would be greatly appreciated.

<table class="checked_out">
  <thead>
  <tr>
    <th>User</th>
    <th>Bike</th>
    <th>Checkout time</th>
  </tr>
  </thead>

  <tbody>
  <% @checkouts.each do |checkout| %>
      <tr>
        <td class="user"><%= checkout.user_id %></td>
        <td class="bike_number"><%= checkout.bike_id %></td>
        <td><button onclick="$('#<%= checkout.id %>').toggle()">Check Bike In</button></td>
      </tr>
      <tr style="display: none" id = "<%= checkout.id %>">
        <td class="needs_reapir_checkbox"><input type="checkbox"> Needs Repair</td>
        <td class="repair_textbox"><textarea rows="1" cols="50"></textarea></td>
        <td><button onclick="">Check In</button></td>
      </tr>
  <% end %>
  </tbody>
</table>

1 Answer 1

2

Your method is a POST or GET?, If your method is POST you need a submit buttom inside a form to send the data otherwise you need a link with the parameters:

Example:

For POST method

<td><%= button_to 'Check Bike In', action: :check_bike_in, id: checkout.id %></td>

For GET method

<td><%= link_to 'Check Bike In', action: :check_bike_in, id: checkcout.id %></td>
Sign up to request clarification or add additional context in comments.

1 Comment

I am trying to do a POST and if I pass i nthe checkout.id then will that pass in the textarea and check box inside that tag? I am just afraid rails params would stop that from being passed in. (usign raisl 4. Sorry new to trying to not use a form_for to do things in rails.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.