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 6847417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:44:32+00:00 2026-05-27T00:44:32+00:00

I am a beginner at rails development and moved from cakephp. In cakephp there’s

  • 0

I am a beginner at rails development and moved from cakephp.

In cakephp there’s something you can do in the layout to automatically include any javascript files that are named the same as either the controller or the action.

For instance in http://www.website.com/post/add

both post.js and post/add.js will automatically be loaded if they exist.

Is there a way to do this in rails? I tried doing a google but didn’t know what to search for and didn’t turn up much.

(Same thing with css)

  • 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-27T00:44:32+00:00Added an answer on May 27, 2026 at 12:44 am

    I’m not aware of this kind of functionality in rails,
    but you can simply do this in a layout:

    javascript_include_tag "#{controller.controller_name}"
    javascript_include_tag "#{controller.action_name}"
    

    it will not check if the file exists, so you can go further and create application helper, and move there a logic of js including and checking if file exists:

    def include_controller_js
     javascript_include_tag "#{controller.controller_name}" if File.exists?("#{Rails.root}/public/javascripts/#{controller_name}.js")
    end
    

    But since rails 3.1 there is an asset pipeline with application.js manifest file, so maybe you would like to read more about it.

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

Sidebar

Related Questions

This is a beginner's rails learning confusion. When I learn rails, from time to
I am a beginner in Rails. In the following code,there is an id which
Beginner rails question: How does one return a file from a controller in rails?
I am beginner of Ruby on Rails and use Windows for development. I do
Good Morning, As a beginner to both Rails and web development, I don't know
Preface: I'm still a beginner to web development, let alone rails so I'm constantly
I'm somewhat of a Rails beginner, and can't shake the feeling that I'm overlooking
Beginner rails/javascript question: Let's say that I have a simple Circle model in a
I am a beginner-verging-on-intermediate rails developer that is working hard to improve my skills.
I am a beginner to ruby on rails.But i am quite comfortable with php,

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.