The bottom line here is you need to use Javascript on the button to load the pop-up
/ modal
; and then show the contents of the JSON file in that new element. How you show that JSON should either be with AJAX
or by using a hidden div
--
Modal

Modal elements are simply divs
positioned absolutely on the page (on top of your other content). They can contain any "normal" HTML you wish, and basically just allow you to give the impression of a pop-up
.
They are really just JS-enabled div elements which appear after event binding. I would recommend using one of these with your button - you'll need to bind the button's "click" event to trigger the modal to load:
#app/assets/javascripts/application.js
$(document).on("click", ".button", function(){
// Trigger modal
});
There are many modal JS plugins you can use:
--
JSON
The way to handle your hidden text is going to be slightly trickier.
There are two ways to do it:
- AJAX
2 Hidden Div
The Ajax way is most efficient (avoids any superfluous data being added to your page); but it's the most tricky.
Here's what I'd do:
#app/assets/javascripts/application.js
$(document).on("click", ".button", function(){
$.ajax({
url: "your_json_url",
dataType: "json",
success: function(data){
// Trigger Modal
}
});
});
This will allow you to create a model & handle any JSON request like this:
#app/controllers/your_controller.rb
respond_to :json, only: :your_json_action
def your_json_action
respond_with @your_code
end
This will basically take the ajax
response, and append it to a form which you'll be able to then show.
-
An alternative is to use a hidden div:
#css
.hidden { display: none; }
#view
<table>
<tr>
<td>test</td>
<td>test2</td>
<td>
test3
<div class="hidden">
your json content here
</div>
</td>
</tr>
</table>