I have an odd situation, but here it is:

```
# a HAML file
:javascript
  #{ if session[:view].blank?
        "$.ajax({
            url: 'url_for params.merge(:action => 'index')',
            dataType: 'script'})"
    else
        "$.ajax({
            url: 'url_for companies_url',
            dataType: 'script'})"
    end }

```

So this is basically nesting javascript inside ruby, inside javascript, inside HAML. It doesn't work because I've got improper nesting of quotes.

1. I imagine there's a better way to do this. Any thoughts?
2. The ajax happening above renders some partials into the current view and **changes the session variable**. How can I update this javascript so it behaves correctly given the new session[:view]?