glarkou
glarkou

Reputation: 7101

Jquery in views

Is it OK (It's working OK but is it proper?) if I place jquery code:

<script>
  $(function() {
    $( "#accordion" ).accordion();
  });
</script>

in my app/views/show.html.rb ?

Is it better to put it somewhere else? I didn't want to put it in layout because I don't need it anywhere else.

Upvotes: 0

Views: 151

Answers (2)

Calvin Davis
Calvin Davis

Reputation: 288

Personally I would put that piece of script into an external JS file and call it from the header of my page in my layout - this way you are keeping your markup and your Javascript entirely separate (in much the same way that you would put all your CSS in an external CSS file and not in style attributes).

But there is no harm in having it where it is. It's really up to you whether you feel it is worth the time and effort to move the script into an external file.

Upvotes: 3

Edgar Villegas Alvarado
Edgar Villegas Alvarado

Reputation: 18354

I think It's better if you put your code in a .js file and include it only when you need it.

Hope this helps. Cheers

Upvotes: 0

Related Questions