简体   繁体   中英

Rails controller.js.coffee not showing up

I just started using Rails.

Inside assets javascripts there's a file (welcome.js.coffee) that says

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

I have placed this function just under

$(document).ready ->
    alert "Hello World"

Inside my application.js file, if I put

//= require welcome

the alert is showed, otherwise no.

I'm I skipping something or even though the welcome.js.coffee file says that logic will automatically be available in application.js I still have to require the file manually?

Your application.js should list

//= require_tree .

as one of the lines, which requires every other file in the directory tree that that file is in. If this line is missing or required, you will have to add it back or else require files specifically (as you did with welcome ) for it to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM