-2

I have a ruby varibale $text = "abcd" I have some condition inside my jquery according to which this text should change. This is so far i have tried.. but no luck.

$("#xyz").click(function() {
  new_text = 'efgh';
  "<% $text = new_text %>"
}

Is this possible. Thanks in advance.

Nidhin S G
  • 1,685
  • 2
  • 15
  • 45

1 Answers1

1

EDIT - Realize this is the opposite of what you want! instead of deleting, it may help someone so I'll leave...

--

You could use the gon gem (Railscast) -

#Gemfile
gem 'gon', '~> 5.0.4'

#app/controllers/your_controller.rb
class YourController < ApplicationController
   def method
      gon.push({
          var_name: "value"
      })
   end
end

#app/views/layouts/application.html.erb
...
<%= include_gon %>

#app/assets/javascripts/application.js
alert(gon.var_name);
Richard Peck
  • 76,116
  • 9
  • 93
  • 147