Jump to content

The ultimate community for Ruby on Rails developers.


How exactly are javascripts called?

ujs javascript

  • Please log in to reply
1 reply to this topic

#1 Jimbollu



  • Members
  • 3 posts

Posted 17 June 2014 - 01:57 AM

Is it the name of the view?


If I have an action that renders the 'panel/show' view, but that view renders the partial 'panel/activities', will that partial call in a javascript file called 'activites'? Purely because of naming convention?

#2 Ohm



  • Moderators
  • 529 posts
  • LocationCopenhagen

Posted 17 June 2014 - 01:40 PM

I guess that you mean the javascript partials that you can get run by adding remote: true to your link_to-helper?

<%= link_to 'Create', some_create_path, remote: true %>

Then if you do not specify anything in the controller, Rails will assume you just mean to render the normal partial, but the js-partial, as you are doing js stuff.


Rails does this quite often with the html views. E.g. in a method called show, if you don't specify anything, it'll render show.html.erb


You can specify your own stuff in the controller, if you want

class SomeController < ApplicationController

  def create
    respond_to do |format|
      format.js { render nothing: true }


This will render the page normally, if done normally, but won't do anything (rendering that is) if called via js.


I hope this clears it up a bit.

Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users