Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing helper file helpers//Users/xxxx/Sites/xxxx/app/helpers/application_helper.rb_helper.rb #18660

Closed
waissbluth opened this issue Jan 23, 2015 · 126 comments

Comments

@waissbluth
Copy link

@waissbluth waissbluth commented Jan 23, 2015

I had a very strange issues out of the blue today. Happens for every controller action; app server and console boot up fine.

It started happening without any changes, and rolling back to a previous commit didn't fix it either. Reinstalling ruby and rails and all the rest of the gems didn't fix it either.

Setup: OSX Yosemite, Ruby 2.2.0, Rails 4.1.9.

Missing helper file helpers//Users/xxxx/Sites/xxxx/app/helpers/application_helper.rb_helper.rb

I finally fixed it by renaming all directories (i.e. Sites to sites) in the apps path to lowercase (except /Users).

Full story here: http://stackoverflow.com/a/27966165/893510

@waissbluth waissbluth changed the title Missing helper file helpers//users/xxxx/sites/xxxx/app/helpers/application_helper.rb_helper.rb Missing helper file helpers//Users/xxxx/Sites/xxxx/app/helpers/application_helper.rb_helper.rb Jan 23, 2015
@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Jan 23, 2015

Can you please provide a sample application that reproduces the error?

@waissbluth
Copy link
Author

@waissbluth waissbluth commented Jan 23, 2015

I apparently can't be done, as when I rolled back to a previously-working
commit the error persisted.

On Fri, Jan 23, 2015 at 1:50 PM, Rafael Mendonça França <
notifications@github.com> wrote:

Can you please provide a sample application that reproduces the error?


Reply to this email directly or view it on GitHub
#18660 (comment).

Nicolás Waissbluth Razmilic

@sevenseacat
Copy link
Contributor

@sevenseacat sevenseacat commented Jan 25, 2015

I've seen this reported several times in the #rubyonrails IRC channel over the last few weeks - haven't been able to pin down a cause.

@amgray
Copy link

@amgray amgray commented Jan 25, 2015

I've had this problem intermittently since upgrading to Ruby 2.2.0 and Rails 4.2.0 (I'm on Yosemite). Renaming my directories to match case (as per http://stackoverflow.com/questions/27871726/strange-error-in-rails-missing-helper) solves the problem - until I reboot when the issue reappears as OS X re-capitalises a directory name.

@etipton
Copy link
Contributor

@etipton etipton commented Jan 27, 2015

Shot in the dark, but possibly related to: https://bugs.ruby-lang.org/issues/10700 ?

@dcunning
Copy link

@dcunning dcunning commented Jan 27, 2015

I'm hitting this error as well on Rails 4.1.9 after switching to Ruby 2.2.0. This line is erroring (filename equals application_helper)

The issue goes away when changing /Users/dan/Projects/my_app to /Users/dan/projects/my_app. My guess is an issue with ruby-2.2.0, unrelated to Rails.

@jgrannas
Copy link

@jgrannas jgrannas commented Feb 1, 2015

Same error here after upgrading to rails 4.2.0

AbstractController::Helpers::MissingHelperError in HomesController#index
Missing helper file helpers//users/joel/sites

my sites folder is "Sites" capitalized

@robmathews
Copy link

@robmathews robmathews commented Feb 3, 2015

I think the issue is unrelated to rails, as I encountered the issue after upgrading our project to ruby 2.2.0 from ruby 2.1.2, NOT changing the rails version.

@robmathews
Copy link

@robmathews robmathews commented Feb 3, 2015

@etipton - the timing of that ruby issue https://bugs.ruby-lang.org/issues/10700 and the bug they are trying to fix exactly match. Looks like the guy tested against a Mac OSX machine that had a case sensitive file system (who does that??) and "fixed" his bug, but broke it for the rest of the world.

@Beengie
Copy link

@Beengie Beengie commented Feb 5, 2015

I only changed the "sites" folder name then renamed it back and it work. I have seen people stating that they renamed the entire directory. It is not needed in my circumstance. Hope that helps.

mv sites sites1
mv sites1 sites

@sgrif
Copy link
Contributor

@sgrif sgrif commented Feb 5, 2015

Yeah, this looks unrelated to Rails.

@sgrif sgrif closed this Feb 5, 2015
@sgrif
Copy link
Contributor

@sgrif sgrif commented Feb 5, 2015

Looks like some other contributors have been digging into this and do think it's an issue in the Rails code-base.

@sgrif sgrif reopened this Feb 5, 2015
@pixeltrix
Copy link
Member

@pixeltrix pixeltrix commented Feb 7, 2015

I'm going to close this because I can't seem to reproduce it - I think it maybe something to do with upgraded Mac OS X versions and the Sites folder capitalisation. The code where the error occurs is here:

def all_helpers_from_path(path)
  helpers = Array(path).flat_map do |_path|
    extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/
    names = Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') }
    names.sort!
  end
  helpers.uniq!
  helpers
end

The path argument is an array of helper folders - in a new application this is just <root>/app/helpers. It looks as though Dir[] is returning case-insensitive matches as described in the Ruby bug and then the extract regexp doesn't match, leaving the full path in the names array rather than application, etc. This then blows up when the application tries to load the helpers.

I've tried to reproduce this on both case sensitive and insensitive file systems.

@pixeltrix pixeltrix closed this Feb 7, 2015
@etipton
Copy link
Contributor

@etipton etipton commented Feb 7, 2015

So... the ruby documentation for Dir.glob(pattern, [flags]) says "Note that this pattern is not a regexp, it’s closer to a shell glob. See File.fnmatch for the meaning of the flags parameter. Note that case sensitivity depends on your system (so File::FNM_CASEFOLD is ignored)"

So although it SEEMS cut-and-dry that the extract pattern will exist in the returned filename, it's actually NOT guaranteed, due to potential case-sensitivity differences. Seems to me like the fix belongs in that method, and that it should do something like:

Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') if file =~ extract }.compact

(not fully tested)

Thoughts?

@etipton
Copy link
Contributor

@etipton etipton commented Feb 7, 2015

I don't have the ability to reopen this but that Ruby documentation makes me think that this situation should actually be handled by Rails.

@etipton
Copy link
Contributor

@etipton etipton commented Feb 7, 2015

btw, great detective work @pixeltrix

@matthewd matthewd self-assigned this Feb 7, 2015
@matthewd matthewd reopened this Feb 7, 2015
@pixeltrix
Copy link
Member

@pixeltrix pixeltrix commented Feb 7, 2015

Without some steps to repro I'm loathe to change anything - however the logic could be improved which is probably why @matthewd just assigned himself this 😄

@matthewd
Copy link
Member

@matthewd matthewd commented Feb 7, 2015

We haven't found a way to prove it 😕, but I remain of the opinion that the current code is Technically Wrong. (It also just doesn't seem like the nicest way of solving the problem, really.)

I'll "fix" the sub, and we can assume it'll make this go away, whatever it was.

@pixeltrix
Copy link
Member

@pixeltrix pixeltrix commented Feb 7, 2015

@etipton I don't think your fix will work because it will miss out helpers - the problem is mismatched case on the application root

@etipton
Copy link
Contributor

@etipton etipton commented Feb 7, 2015

Oh, right... damn. Maybe the extract regexp should just have a /i ?

I also agree that the way the whole thing works seems kinda wonky.

@sambecker
Copy link

@sambecker sambecker commented Mar 7, 2015

Same issue. Rails 4.2 and Ruby 2.2.0.

I recently switched from Unicorn to Puma which crashed soon after and then I restarted my computer. My app, which hasn't had any serious issues in months, will no longer start. I don't have my app in the Site folder, however, by following the logic above, it looks like my capitalized user or username folder is the culprit, i.e., /Users/Sam/rails/app_name

Do I really need to lowercase Sam here? I would really like to avoid that for obvious reasons. Is there no Rails or Ruby cache that can be cleared? This is now a permanently corrupt app?

*** Ok, quick update in case anyone cares, just fixed this issue by renaming the enclosing folder rails which had always been lowercase to a new name and then back to rails, not sure how cases played into my issue, if at all ***

@robmathews
Copy link

@robmathews robmathews commented Mar 7, 2015

You might read this SO. Some of the people seem to have been able to simply
rename the directory w/o changing the case.
http://stackoverflow.com/questions/27871726/strange-error-in-rails-missing-helper/27909917#27909917

On Fri, Mar 6, 2015 at 11:14 PM, Sam Becker notifications@github.com
wrote:

Same issue. Rails 4.2 and Ruby 2.2.0.

I recently switched from Unicorn to Puma which crashed soon after and then
I restarted my computer. My app, which hasn't had any serious issues in
months, will no longer start. I don't have my app in the Site folder,
however, by following the logic above, it looks like my capitalized user or
username folder is the culprit, i.e., /Users/Sam/rails/app_name

Do I really need to lowercase Sam here? I would really like to avoid that
for obvious reasons. Is there no Rails or Ruby cache that can be cleared?
This is now a permanently corrupt app?


Reply to this email directly or view it on GitHub
#18660 (comment).

@xn
Copy link

@xn xn commented Jun 22, 2016

Yes. I'm not yet on 5.0, so 4.2 is still broken for me.

@xn
Copy link

@xn xn commented Jun 23, 2016

Sorry, #24822 is still broken for me and my find_template_paths works.

@nanom1t
Copy link

@nanom1t nanom1t commented Jul 7, 2016

I have the same problem with Ruby 2.2.3 and Rails 4.2.5.1.

All power and magic of RoR in one place.

@cynical89
Copy link

@cynical89 cynical89 commented Aug 11, 2016

I had this issue using rails 4.2.5.1 and ruby 2.2.4. When navigating using Git bash, if I navigated to the "Documents" folder using "documents", I got the error. I corrected it by navigating using the correct capitalization of folder names. no other changes.

xn added a commit to xn/rails that referenced this issue Aug 20, 2016
@xn
Copy link

@xn xn commented Aug 20, 2016

This accounts for namespaces

      def all_helpers_from_path(path)
        helpers = Array(path).flat_map do |_path|
          Dir["#{_path}/**/*_helper.rb"].map! { |file|
            sub_folder = file.gsub(_path.to_s, "").gsub(File.basename(file),"").gsub(/^\//,"")
            module_name = File.basename(file, '_helper.rb')
            "#{sub_folder}#{module_name}"
            }.sort!
        end
        helpers.uniq!
        helpers
      end
@stephenhmarsh
Copy link

@stephenhmarsh stephenhmarsh commented Jan 12, 2017

This happened to me suddenly after no apparent system or dependency changes.

  • Git 2.10.2
  • Ruby 2.3.3
  • Rails 4.2.7.1

The SO fix worked for me:
mv reponame reponame1
mv reponame1 reponame

@brunomilani
Copy link

@brunomilani brunomilani commented Mar 6, 2017

IN WINDOWS - SOLUTION

Example Folder Application:

Users/username/apps/blog

I was starting my folder application in bash all lowercase path. The correct is in windows use the folder Users with the first uppercase letter.

cd c:/Users/username/application/blog

@sampierson
Copy link

@sampierson sampierson commented Mar 9, 2017

For me this was a Mac OS X quirk. I recall that I created a rails project in a folder called marketing/projname then later renamed marketing to Marketing. Everything worked fine when running the project in Docker but then one day I tried to run it natively and hit this bug. Here is my fix:

cd ../..
mv Marketing x
mkdir Marketing
mv x/* Marketing
rmdir x

This fixed the problem. It should have not effect but I believe Mac OS X for some reason remembers the original case that a folder was created with and regurgitates it on occasion.

@neongrau
Copy link

@neongrau neongrau commented May 26, 2017

Just upgraded an app from Rails 4.x with Ruby 2.0.x to Rails 5.0.2 with Ruby 2.3.3 on Windows and i'm seeing this error on some machines with Windows Server 2016.

Strangely not all machines my machine had an uppercase letter in the directory. Other machines had an lowercase and i needed to rename to uppercase to work. Then another machine had just lowercase and needed to rename to uppercase. Another machine worked from the start.

Isn't there a known fix with ruby instead of wildly renaming directories?
Quite weird that this issue happens on macOS and Windows though Windows is always case-insensitive (unless maybe really weirdly configured to be which no one with a sane mind would dare).

@neongrau
Copy link

@neongrau neongrau commented May 30, 2017

I've now resorted to a monkey patch and added the "i" option to the RegEx.
With that the problem seems to go away. Which of course wouldn't work for people running case sensitive file systems. Although i don't know if they even see this issue.

module ActionController
  module Helpers
    module ClassMethods
      def all_helpers_from_path(path)
        helpers = Array(path).flat_map do |_path|
          extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/i # PATCH: just added the "i" option to the RegEx
          names = Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1'.freeze) }
          names.sort!
        end
        helpers.uniq!
        helpers
      end
    end
  end
end
@neongrau
Copy link

@neongrau neongrau commented May 30, 2017

Though my Rails app is starting up and working so far i noticed another side effect of the underlying problem.

In some Helpers and Models i have constants defined and i get "previously initialized constant..." warning for each and every Helper and Model because it seems to try and load them twice.
Once with lowercase and once with uppercase path. Not breaking anything just noise.

I could easily reproduce it by firing up a rails console in production environment on Windows Powershell by arbitrarily writing any letter in uppercase at "cd"

e.g.

PS C:\>cd railsapp
PS C:\railsapp>rails c production

works fine

while

PS C:\>cd Railsapp
PS C:\Railsapp>rails c production

will trigger complaining about constants

@neongrau
Copy link

@neongrau neongrau commented May 30, 2017

So i ended up removing the monkey patch.

From now on i have to keep in mind that ruby will treat any file system as case-sensitive.
So using uppercase letters is technically just fine. You just have to make sure you stick 100% to that and never type it differently.

@PascalPixel
Copy link

@PascalPixel PascalPixel commented Jun 23, 2017

The new APFS is case-sensitive in macOS 10.13 beta2 and giving this bug for me.

helpers//users/username/github/repo_name/app/helpers/active_admin/views_helper.rb_helper.rb
/Users/username/Github/Repo-Name/app/helpers/active_admin/views_helper.rb

Not all-lowercase and changed - to _

Manually applying this patch fixed it for me #24821

@IkarosAnastasios
Copy link

@IkarosAnastasios IkarosAnastasios commented Jul 26, 2017

In Windows 10 - I was able to (finally) use Ruby on Rails after making sure the path I was using in my terminal matched case exactly with the actual path.

i.e.
C:\Users\Username\Desktop\filefolder...

versus neglecting capitalization (as I was doing)

C:\users\username\desktop\filefolder...

@cperson
Copy link

@cperson cperson commented Aug 17, 2017

@IkarosAnastasios that did it for me on Windows 8 as well.

@xn
Copy link

@xn xn commented Aug 18, 2017

@Superpencil did you try the code I posted above at all?

def all_helpers_from_path(path)
        helpers = Array(path).flat_map do |_path|
          Dir["#{_path}/**/*_helper.rb"].map! { |file|
            sub_folder = file.gsub(_path.to_s, "").gsub(File.basename(file),"").gsub(/^\//,"")
            module_name = File.basename(file, '_helper.rb')
            "#{sub_folder}#{module_name}"
            }.sort!
        end
        helpers.uniq!
        helpers
      end
@PascalPixel
Copy link

@PascalPixel PascalPixel commented Aug 19, 2017

@xn I did and it didn't work for me <3

@xn
Copy link

@xn xn commented Aug 21, 2017

What mechanism is changing dashes to underscores?

@sponeil
Copy link

@sponeil sponeil commented Jan 19, 2018

This may be a silly question. Why would anyone bend over backwards to do it like this anyway?

extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/i
names = Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1'.freeze) }

You know exactly what prefix and suffix you want to strip and the glob will ensure that every file starts and ends with them. It is easier, cleaner, and more efficient to strip them by length than it is to build a pattern (which doesn't even work properly on every file system):

suffix = "_helper.rb"
names = Dir["#{_path}/**/*#{suffix}"].map { |file| file[(_path.size+1) .. -(suffix.size+1)] }

@fmoudoute
Copy link

@fmoudoute fmoudoute commented Jun 18, 2018

This happened to me after i updated Rubymine. All i did was changing the folder of my website from HelloWord to helloword. Removed capital and other symbol and it works fine.

@vlad-at-work
Copy link

@vlad-at-work vlad-at-work commented Jun 18, 2018

@nynhex
Copy link

@nynhex nynhex commented Jun 18, 2018

Probably time to nuke this one.

@malibeg
Copy link

@malibeg malibeg commented Jan 31, 2019

Had same problem with ruby 2.3.3, 'rails', '4.1.9' on Windows 10 Pro newly setup system. Never had issue before with same app.

Solved issue but correcting case in cmd.exe window from
C:\projects\app
to
C:\Projects\app

@JonRowe
Copy link
Contributor

@JonRowe JonRowe commented May 21, 2019

For future searchers... This happened to me using rvm, I'd accidentally activated a gemset using an uppercase name, this "worked" as OS X is case insensitive but caused rails to have this load error.

@jpaulomotta
Copy link

@jpaulomotta jpaulomotta commented May 24, 2019

This issue happened to me today using rails 5.2.3 and ruby 2.5.1
It never happened before in the app I'm working.

Stoping spring solved the problem
Run on the command line:
$ spring stop

@kelvin8773
Copy link

@kelvin8773 kelvin8773 commented Aug 5, 2019

$ spring stop solved my problem. (Same version Ruby & Rails)

@The-Noble-K
Copy link

@The-Noble-K The-Noble-K commented Aug 29, 2019

$ spring stop solved the problem for me too. Ruby 2.6.3 / Rails 5.2.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet