documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.io/jammit/
MIT License
1.16k stars 197 forks source link

String interpolation not working #216

Closed rottmanj closed 12 years ago

rottmanj commented 12 years ago

For some odd reason, string interpolation is not working from with in my js files.

I have the following bit of javascript. What should happen is that the string #{validate_username_broker_userdesk_accounts_path} should be calculated and the string replaced. How ever this is not working.

$("#user_username").focusout(function(){
    username = 
    $.ajax({
        type: 'POST',
        url: "#{validate_username_broker_userdesk_accounts_path}",
        data: { username : $('#user_username').val() },
        success: function(data){
            if(data.results)
            {
                $('#user_username').addClass( "ui-state-error" );
            }else
            {
                $('#user_username').removeClass( "ui-state-error" );
            }
        },
        dataType: 'json'
    }); 
});

This js files is located in public/javascripts/broker/userdesk/accounts/account_user_new.js

This is what my assets.yml looks like

embed_assets: on

javascripts: accounts_user_new:

jashkenas commented 12 years ago

Nope -- JavaScript files are JavaScript files -- they don't get preprocessed by Ruby.

If you'd like to pass app-specific data for your JavaScript to use, just load it as JSON into your page.

rottmanj commented 12 years ago

jashkenas,

Something to add to this, when even using js.erb string interpolation still does not work.