1

I have the following code in a view file of my rails application:

  <td>
    <div class="file_description"><%= object.metadata['description']%>
    <button    type="button" class="btn btn-default edit_description">Edit</button></div>
    <div class="file_description_update"
      <%= form_tag({:action => 'update_file_info'}, multipart: true) do %> 
        Update File Description: <%= text_area_tag :description %>
        <%= hidden_field_tag :s3_path, file %>  
        <%= hidden_field_tag :prefix, @prefix %>
        <%= submit_tag 'Submit' %> </td> <br />
      <% end %>
    </div>
  </td> 

I need to bind my Edit button on click event with the class file_description_update for each file I will be working with. Any views on the simplest way to do that in rails? Thanks

1 Answer 1

3

You can bind event with jquery. Add this to your application.js, you can link onclick event to all your button with class "edit_description".

$(function(){
  $('button.edit_description').click(function () {
    alert($(this).parent().next('div.file_description_update').children('form').html());
  });
});

DEMO fiddle

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the reply. Would this solution allow me to open up a form (for updating description of a file --which is what i want basically as the file-description-update class is currently hidden using css) on clicking the edit button and then allow me to update the description for a file using that form?
Yes, you can. In the click event, you can show the div you have hidden. But if you want to change the file, you must submit the form and refresh the page, or you must using some ajax upload plugin such as "jquery file upload".

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.