Rails 3.1 - what is the best way to access controllers' variables in coffeescript?

You can do it using coffeebeans. Just add it to your Gemfile: gem 'coffeebeans' And then create the file as you want: #app/views/posts/create.js. Coffee $("#form__").hide().

1 This is great, it works exactly as I expected to. Just one thing : the code above does not work in my case, because the id to identify was in the the format #form_Post_3, so I needed to use $("#form__").hide(), without the #{}. – obo Dec 14 at 20:07 I've updated the answer with your corrections.

– Pedro Nascimento Dec 14 at 20:58 To make it work on Heroku, I needed to add the gem 'therubyracer' in my Gemfile. – obo 22 hours ago.

If you want to use erb in your coffeescript files you have to append the erb extension to the file. So your file should be renamed to create.js.coffee.erb. And then you can do something like: $ -> alert('') It should work fine.

See docs for further information. EDIT I think I've missed a point in your question. If you want to access instance variables in your js files, unfortunately you can't.

See this answer for further information.

I edited the question with more precisions on what I tried to do after reading your link. Thanks for you reply. – obo Dec 13 at 13:45.

When you're responding to js it means it renders the create.js. Coffee as a view. You don't need to add .

Erb to the end to use erb code inside, like this: $("#form__").hide() You are probably confused by the @ in coffeescript, it just means this. Or this in javascript. And the #{ .. } code is interpreted only by coffeescript not by ruby (as you're used to in HAML), so the code you have would output this in javascript: $("#form_" + this.

Commentable"class" + "_" + this.commentable. Id).hide().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions