-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.

4
  • 4
    ruby is server side... you can't do something like that unless using ajax... Commented Jun 6, 2014 at 9:25
  • but i can set a string directly.. if that is possible i can pass new_text right? Commented Jun 6, 2014 at 9:37
  • The code inside <% %> will only execute at load time.. Commented Jun 6, 2014 at 9:39
  • Indirectly you can achieve this. See stackoverflow.com/questions/4959770/… Commented Jun 6, 2014 at 9:41

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

No problem - hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.