Not sure if I could reliably reproduce this, but sometimes when I switch branches in development all requests start throwing an undefined method error inside of a helper. The method is present on both branches. I am using global helpers (helper :all).
To fix the issue, I go into the helper file and save any change. Usually I just add a new line to the end of it. After saving, it works fine. Seems like a caching issue.
Has anyone else seen this and resolved it? I am on Rails 4.2.1. As far as I know this only happens in development mode.
Since you are using Rails 4.2, spring has probably cached the code from the old branch. After switching to the new branch remember to run:
spring stop
Spring will restart itself the next time you run the server, tests, or other Rails commands.
Related
I have an app with a rails engine i use. I've stripped them down pretty much to the bone, but i get a fault when I start the engine up with multi-threading enabled. I faults out with missing constant the model name i'm calling from the controller. I've reduced it down to just calling the Model.all.pluck(:id). And still get the fault. The models are being invoked via an Ajax call to the controller.
The app runs correctly if i refresh the page and continue, never faulting out again, that I can see.
I think it's actually a multi-treading issue, I'm using Rails 4.1, Ruby 2.12 and Puma 2.8.2 and postgress.
This is happening on my development system a macbook. I will don't see it in the heroku logs when I deploy, but ??
Now somewhat curious. I've made the issue go away, by forcing the app to load each model in the engine, one at a time. Things seem to run smoothly after that.
Any suggestions on how to dubug this
This is directly linked to config.eager_load settings of your app. In production it is set to true so you do not have the circular dependency problem, in development it is generally set to false and that's where rails auto loading systems may trigger this kind of error.
I do believe (though I'm not certain) that you can solve this by not declaring nested classes and modules in one single line
Instead of
class MyModule::MyClass
...
end
Use
module MyModule
class MyClass
...
end
end
My project has always used grails 2.0.1 and my controllers define their actions as methods not closures. Previously these actions have always worked (i.e. the browser can render the correct gsp page first going through the action method in the controller).
Recently we've noticed that the bespoke actions no longer work, the browser reports a '404 resource not found'. We're still on grails 2.0.1, this is confirmed by 'loading grails 2.0.1' comments in every grails command that is run. Although there are some controller/domain/services changes, none of those changes should affect the use of action methods. From what I can tell, we've not downgrade the version of grails/groovy.
If I change the actions to be defined as closures, then it works fine. But I'm not happy with this as my solution as methods are the preferred way and it used to work.
I've tried the usual approach to grails weirdness: proper clean and rebuild, but no joy. Also, this is an issue in both eclipse and unix envs (project delivered as a war run by the grails command), so it must be something in the project files but I cannot spot anything that has changed.
Any suggestions what could have happened to my project and how to resolve?
I've finally tracked my problem down to an aspect I was using to monitor long running method calls. I had changed the pointcut to include 'within(com.mydomain.domain..*)' which is where my Controller class resides. This appeared to stop my bespoke links from working, not entiring sure why. I hadn't intended this, I just wanted my pointcut to include all domain class methods but I'm happy to sacrifice that in order to get controller method actions working again.
I've resolved this issue by amending my pointcut.
I've got a Rails 3.2.3 app with the default_locale set to :nl. When I start the app using Thin or Unicorn, the app's locale is set to :en. When I use Webrick, the locale is correctly set to :nl.
This change is triggered by a commit that updates several third-party gems, although I have not been able to single out any one gem upgrade in particular -- I can reverse each of them individually and get the same result. However, when I checkout the offending commit's parent, all is well too.
When I run the app on a remote server in production mode, it all works fine, so it seems to be local to my machine.
I have removed every single installed gem and re-installed them all, which made no difference.
Does anyone have any idea what might trigger this behaviour? And especially why using webrick or unicorn would make a difference?
Edit: I have pinpointed the bug to be triggered by upgrading Draper from 0.11 to 0.12 (issue at Github). Not sure if it is also the cause.
http://labs.revelationglobal.com/2009/11/13/unicorn_and_i18n.html
This problem has occured to me before wich was triggered by the "active_admin" gem you might want to use an earlier version to prevent this, I do not really know wich one so you can play around with it a little.
another option would be to set the active_admin locale in a before_filter,
config.before_filter :set_admin_locale
And set_admin_locale is in the application_controller:
def set_admin_locale
I18n.locale = :nl
end
hope it helped
I managed to track this problem down to a bad practice in my own Rails app that caused a bug by upgrading the Draper gem. There's a full explanation in the Draper documentation.
is the console in rails (~ rails c) dynamic? For example; if I open the console and then make changes to a model will it pick these changes up or do I have to exit out of the console and run rails c again for it to pick up the changes in the model?
You will need to call the reload! method in the console to reload the changes. This method's magic is automatically called by rails server in development mode.
As a comment's pointed out beneath and another answer here, if you change things to do with the environment of the application, such as adding new gems to the Gemfile, making changes to anything in config or adding a new plugin then you'll need to restart the console. Any changes to app will be reloadable with reload!
If you were using this particular way to test that a method was working, I wouldn't. Tests (as in, the Test::Unit or RSpec) variants are much nicer because you have a reproducible way of running them again and again. rails console is great for one-off testing, but if you want to write a maintainable application then write tests.
I have AS (as a plugin) working in another app just fine (I dont remember this
issue...) - its also using Rails 2.3.9, on same dev box.
Now trying to add it to a new app and getting this error when running
the webrick, script/server:
/Users/kimptoc/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.9/lib/
active_support/core_ext/module/aliasing.rb:33:in `alias_method':
undefined method `number_of_pages' for class `Paginator' (NameError)
from /Users/kimptoc/.rvm/gems/ruby-1.8.7-p302/gems/
activesupport-2.3.9/lib/active_support/core_ext/module/aliasing.rb:
33:in `alias_method_chain'
from /Users/kimptoc/Documents/ruby/borisbikestats/vendor/plugins/
active_scaffold/lib/extensions/paginator_extensions.rb:9
I couldn't find any previous references to this error.
Embarassingly I dont know which version of AS I am using successfully... it says 1.2RC1 in the CHANGELOG file, but I seem to remember trying a few of the forks...(is there somewhere I can see which fork is in use...). I have tried using the the 'main' activescaffold in the new project, but it fails as above, but so does using the same plugin that is in the working project :(
Thanks in advance for any pointers as to what I am doing wrong.
Thanks,
Chris
PS Just realised that new Rails was using Rails 3 and old/working one was 2.3.9. It seems you need to use an alternate branch of AS for Rails 3, like this : https://github.com/vhochstein/active_scaffold/wiki
This is just a guess, but built in pagination was removed in Rails 2 as I recall, and you needed to install the classic_pagination plugin to get that functionality back.
I only used ActiveScaffold once, but the error there says paginator_extensions.rb ... it's probably monkey patching the old Rails paginator? Therefore the class exists but the number_of_pages method doesn't.