Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Ruby on Rails : how to pass value to javascript

I want to pass the value from <%= controller.controller_name %> <%= controller.action_name %> to javascript as below

return (document.body.className += " load-done 
            '<%= controller.controller_name %>' '<%= controller.action_name %>'
        ");

but it doesn't work, can anyone advise on this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The question is lacking information so I just guess you want to pass some data directly from the controller to your JS code. There are two "normal" ways to do this. The first is to do a direct call to the controller as a http call and return the response as a json. The second method is to pass the data as a class variable, then you can access it in the views folder from the html files. Here you can pass the variable to a div, span or whatever and access it in the JS by finding the html tag in the JS like so:

# controllers: 

def some_controller_method
  @temp = 'example data, could be any type'
end

# views
<%= content_tag :div, class: "some_class", data: {temp: @temp} do %>
<% end %>

# JS
$('.some_class').data('temp')
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!