0

In my rails 3.1 App, I have 3 different javascript files for my html table. Let say, table1.js.coffee, table2 and table3.

In my application.js file, I have :

// = require table

And in my table.js.coffee.erb, I wish to do something like that :

// = require <%= 'table2' %>
// or (more useful)
// = require <%= Settings.js_table %>

Like this, I will be able to change my table's behavior from an extern config file. For the moment, it's not working. And I was wondering if it's possible ?

Thank you!

1

1 Answer 1

1

It won't work.

Files in the pipeline are compiled on the first request, based on their contents (and any resolved erb) at that time.

If you reference something inside a pipeline file it will not update if that is changed elsewhere.

Edit in response to comment:

Sorry, I should have been clearer. The general case of this won't work.

In the case of using it with require, the require statement is a Sprockets specific directive. It is processed by Sprockets before the erb handler gets it.

The directive requires one argument - a string. In this case you have passed 3 arguments to the require directive: an opening erb tag, a quoted string, and a closing erb tag.

Thats why you get a 3 for 1 argument error.

The best (and possibly) only way to include files dynamically at run time is from your view layer.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm aware of that. But even the = require <%= 'table2' %> doesn't work. I catch this error : ArgumentError: wrong number of arguments (3 for 1)

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.