mardi 29 octobre 2019

Call an action on button click in ruby on rails

I have an action defined in my lib directory. The action is used to send a get request in the server. I want to execute the function on button click. How can I do this? I know this is not the right approach. I am new to rails.

show_document.rb (in lib directory)

class Legaldoc::ShowDocument

def view_document(sessionID, token_document)
    require 'rest-client'
    require 'zip'
    res = RestClient::Request.execute(
        :method => :get,
        :url => "http://myurl.com",
        :headers => {
            :ldsessionId => sessionID,
        }
    )
  end
end

in my view file

<%= link_to 'Button', '#', :onclick => "view_document(sessionID, token_document)" %>

Aucun commentaire:

Enregistrer un commentaire