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 · 121 comments

Comments

Projects
None yet
@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 from Missing helper file helpers//users/xxxx/sites/xxxx/app/helpers/application_helper.rb_helper.rb to Missing helper file helpers//Users/xxxx/Sites/xxxx/app/helpers/application_helper.rb_helper.rb Jan 23, 2015

@rafaelfranca

This comment has been minimized.

Member

rafaelfranca commented Jan 23, 2015

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

@waissbluth

This comment has been minimized.

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

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

This comment has been minimized.

Contributor

etipton commented Jan 27, 2015

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

@dcunning

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Member

sgrif commented Feb 5, 2015

Yeah, this looks unrelated to Rails.

@sgrif sgrif closed this Feb 5, 2015

@sgrif

This comment has been minimized.

Member

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

@robmathews

This comment has been minimized.

@pixeltrix

This comment has been minimized.

Member

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

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

This comment has been minimized.

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).

@hubmark

This comment has been minimized.

hubmark commented May 25, 2016

I tried everything and nothing worked except these simple instructions http://quick.as/yvyqsn7j

@schneems

This comment has been minimized.

Member

schneems commented Jun 6, 2016

I'm hitting this right now with codetriage/codetriage. Crazy thing is if I clone into a new directory and set it up, it runs fine (shrug)

@innergap

This comment has been minimized.

innergap commented Jun 22, 2016

I noticed that in git bash i go to the location by not capitalizing my directories, that is 'c:/user/sites/whatever' and it seems to look at that capitalization. When I actually go to the directory to run the project by giving the proper capitalizations in git bash 'cd c:/Users/Sites/Whatever' and then run the project, it works fine

@xn

This comment has been minimized.

xn commented Jun 22, 2016

To be clear, this still hits me and I'm on OSX. @aharpervc, any chance to address this in your PR's?

@aharpervc

This comment has been minimized.

aharpervc commented Jun 22, 2016

@xn to be clear, you're saying #24821 is still broken for you, right, but your latest version of find_template_paths does work?

@xn

This comment has been minimized.

xn commented Jun 22, 2016

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

@xn

This comment has been minimized.

xn commented Jun 23, 2016

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

@nanom1t

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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.

@Superpencil

This comment has been minimized.

Superpencil 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

This comment has been minimized.

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

This comment has been minimized.

cperson commented Aug 17, 2017

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

@xn

This comment has been minimized.

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
@Superpencil

This comment has been minimized.

Superpencil commented Aug 19, 2017

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

@xn

This comment has been minimized.

xn commented Aug 21, 2017

What mechanism is changing dashes to underscores?

@sponeil

This comment has been minimized.

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

This comment has been minimized.

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.

@vladdypwnz

This comment has been minimized.

vladdypwnz commented Jun 18, 2018

@nynhex

This comment has been minimized.

nynhex commented Jun 18, 2018

Probably time to nuke this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment