Justin Lee
Justin Lee

Reputation: 21

Inserting variables into .html.slim file that are declared from a different directory

I am new to Ruby. I have a .html.slim file that has some numerical values that I want to replace with variables declared in another .rb file. I have this rough setup:

company/app/views/landing_pages_hello/_hello.html.slim
company/lib/random/variables.rb

company/lib/random/variables.rb

class A
  MY_SALARY = 5000
end

company/app/views/landing_pages_hello/_hello.html.slim

table
  tbody
    tr
      td
        = ...
        title=("My salary is $5000")

So I am wondering how do I replace the "5000" in the _hello.html.slim file with the variable MY_SALARY from the variables.rb file.

Upvotes: 1

Views: 750

Answers (1)

Jared Beck
Jared Beck

Reputation: 17528

The Getting Started with Rails guide explains how to pass variables from a controller to a view. I'd recommend reading most of that guide now. There are other guides you'll want to read later as you learn more.

The Slim documentation explains how to use variables in your views.

Upvotes: 1

Related Questions