1

How I can integrate ruby variable into a js file. I would like to render a partial relative to the current step of registration of my User. But I can't succeed it, Rails do not translate @flat.current_step in his value (which is a integer). Any ideas ?

$('.flats').replaceWith("<%= j render partial: 'flats/steps/step#{@flat.current_step}' %>");

Error

ActionView::Template::Error (Missing partial flats/steps/_step#{@flat.current_step}
4
  • What do you mean "can't succeed"? Commented Jun 2, 2018 at 12:36
  • Well the code is not working, I have a error of template Commented Jun 2, 2018 at 12:37
  • 1
    "I have a error of template" - how are we to know what's wrong? Post the error, in its entirety. Commented Jun 2, 2018 at 12:42
  • Rails do not translate @flat.current_step in his value (which is a integer) Commented Jun 2, 2018 at 12:54

1 Answer 1

4

Ruby does not interpolate the #{} when wrapped in single quotes. Change your call to:

$('.flats').replaceWith('<%= j render partial: "flats/steps/step#{@flat.current_step}" %>');
Sign up to request clarification or add additional context in comments.

3 Comments

@stigGaret: nope, you had something different. This should work (given that @flat.current_step does indeed result in an integer).
No se, I've tried to replace the line by an alert("<%= @flat.current_step%>") and is well working !! (The result should be 3)
ActionView::Template::Error (Missing partial flats/steps/_step#{@flat.current_step}

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.