I have 2 controllers that render a single view and I need the view to change depending on my controller. What I have in mind is to have a JS var in my view that I can set depending on which controller was called.
To be a bit more thorough on my explanation, I need to get a string value set inside a var so I can use it like this (in a piece of JS on the application.js):
if (value_i_set_in_controller == "controller1") {
// do something
} else {
// do something else
}
Any hints? Until know I have been finding Rails pretty easy.
EDIT
I need to explain a bit more.
I have some js in my application.js which renders some objet.
$('#calendar').fullCalendar({
...
// a future calendar might have many sources.
eventSources: [{
url: '/DYNAMIC_PATH',
color: 'yellow',
textColor: 'black',
ignoreTimezone: true
}],
I render this simply by having a calendar view with this :
<div id='calendar'></div>
I was thinking of doing something like this in the calendar view:
<div id='calendar'></div>
<script type="text/javascript">
var calendar_source = <% @dyn_path %>;
</script>
Evidently it does not work… with this I would be able to read calendar_source var and us it in my js to set the eventSources properly.
I think you’re just missing quotes :
Anyway I need this kind of assignation often, it works perfectly 🙂
If it still doesn’t work, look at the generated code and the JS console (firebug, chrome debugger …)