Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7428913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:53:10+00:00 2026-05-29T08:53:10+00:00

I want to make a general controller that can be called after the page

  • 0

I want to make a general controller that can be called after the page was loaded (with AJAX) and update different stuff on the page depending on which controller called it.

The purpose is to allow better page and fragment caching, while displaying custom elements for the users.

My framework looks like this:

controllers/general_ajax_controller.rb
views/general_ajax/on_page_load.js.coffee
                 ./_update_some_stuff.js.coffee

The on_page_load action in the controller handles the logic of figuring out which partials to load and the view will render the partials.

In the on_page_load.js.coffee view I have this code (simplified):

<%= render "update_some_stuff" %>

which should render the partial. Instead I get this error:

  ActionView::Template::Error (SyntaxError: Reserved word "function" on line 2):
  app/views/general_ajax/on_page_load.js.coffee:1:in `_app_views_general_ajax_on_page_load_js_coffee___2304196970850216490_70321203283120'

I think that the coffeescript is compiled before including it in the view (which is coffee and does not support compiled js)

If I change the extension of the on_page_load view to .js.erb then it works.
(Oddly enough, I have to restart my server before it works, do you know why?)

Do you think this is an issue in coffeescript or is it bad practice and therefore not supported?

As a side discussion, what do you think of my approach to dynamic scrips?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:53:11+00:00Added an answer on May 29, 2026 at 8:53 am

    That’s because _update_some_stuff.js.coffee is interpreted and converted to Javascript. When it is inserted into on_page_load.js.coffee it raises an error because vanilla Javascript code is not compatible inside a Coffee-Script file (the function keyword in this case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a general error handling package that should be called from
I want to make an application with plugins that also can have plugins (which
I want to make an app which (amongst other things) can parse feeds loaded
I want to make an etag that matches what Apache produces. How does apache
I want to make a table in SqlServer that will add, on insert, a
I want to make an entity that has an autogenerated primary key, but also
I want to make a general method to do PARTIAL updates of a document
I want to make an MVC route for a list of news, which can
In my forms, I want to make HTML labels bold in general, but not
I want to make a table that simply has two integer columns to serve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.