On May 29, 2009, at 4:13 PM, Marnen Laibow-Koser wrote:
> Mk 27 wrote:
>> Is there a shortcut for this kind of thing:
>>
>> <%if X=42%>
>> <script type="text/javascript>
>> some_funct()
>> </script>
>> <%end%>
>
> I'm not sure, but if there isn't, a helper method would be trivial to
> write. However, you probably shouldn't be writing that sort of code
> in
> the first place:
>
> * "if X=42" should be "if x == 42".
> * JavaScript belongs in external files, not in the view. (Just like
> CSS
> -- although you *can* include it inline, it's a very bad idea.)
> * Depending on what you're doing, this may be too much logic for the
> view.
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> [email protected]
On May 29, 2009, at 4:26 PM, Mk 27 wrote:
> Sorry, yeah, that should be ==
>
> some_func() is in an external file, but it does need to be called from
> in the view. Your assertion that "javascript does not belong there"
> is
> patently ridiculous since many of the normal rails functions deploy
> JS/AJAX, in the view. A central conceit of rails is XMLHttpRequest,
> and
> it is deployed IN THE VIEW.
>
> I will investigate writing a helper, thanks.
It already exists:
<%= javascript_tag("some_func()") if x == 42 -%>
-Rob
Rob Biedenharn http://agileconsultingllc.com
[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---