Custom devise views ignored in production enviroment - ruby-on-rails

I'm using custom devise views created by the rails-prelaunch template - https://github.com/RailsApps/rails-prelaunch-signup
In development, everything works fine. I see the devise views I'm expecting (from the views/devise folder).
However, as soon as I switch to production, the app starts using the default devise gem views.
Any ideas as to what might be going on?
Thanks!

I re-created the app, and things just worked. It turns out that there was a problem accessing the template.
I still don't know why the common solutions didn't work, as things seemed to be setup correctly.

Related

Rails not auto loading engine code

I have some rails apps and rails engines, their structure is like this:
rails_app_1/
rails_app_2/
etc......
rails_engine_x/
rails_engine_y/
rails_engine_z/
rails_engine_w/
Each rails_app loads a subset of these engines, so for example rails_app1_1 Gemfile may have this code
gem 'rails_engine_x','0.0.1', path: '../rails_engine_x'
gem 'rails_engine_y','0.0.1', path: '../rails_engine_y'
Now the problem is that on development mode, when changing some code, it seems that code auto loading is broken and I get strange errors that are fixed when I close the server and open it again. For example I may get some errors like (Constant Foo is not defined-where it is actually defined-), and other times I got some error(undefined method serialize_from_session for #<Class:0x00000009762628>) which is a method from devise defined on User class which was working normally, only when changing the code in development mode while the server is running then it is not defined. So I need to restart the server to get the code reloaded correctly. Any help on this? I read about rails auto loading but couldn't find a clue.
Ok the problem is solved, it was because of a strange initializing code that was trying to include some modules manually, when I changed it, every thing worked.

Models not reloading in development in Rails (3.2.11) project

I've searched fairly extensively for any advice and have yet to find it so, here goes:
My Rails project fails to automatically reload models in development. Reloading them currently requires a full server restart.
Previous instances of this issue have been related to non-activerecord files placed in the models directory, though this is not the case for me.
config.cache_classes is properly set to false in my development config file. Views and controllers reload without issue.
All of my rails components are version 3.2.11. I have tried disabling all of my development-specific gems to no avail. This is obviously not a productivity stopper, but it is quite an annoyance. Any help appreciated and I am happy to provide more information if it would help, though I am not using any exotic gems.
Thanks!
Some possibilities:
You are not really running on developement environment
You are changing a model within a namespace and didn't told rails to autoload the path
You are changing a file that is included in your class, not your class directly (or any of the many variants for this)
You are caching classes
Considerations:
Things might change according to the webserver you are using
How do you know it's not reloading?
I ask my question because I was having the exact same issue when I was trying to insert a debugger into what I thought was a piece of code that was being executed. I assumed the model wasn't being reloaded since it was not hitting the debugger but it was actually a call back that was redirecting me around the code with the debugger line in it.
So, it might be something other than your models not being reloaded.

Is it possible to programmatically clear Rails 3 layouts and views cache?

I have a Rails 3 based CMS that allows users to create and modify layouts and views. These layouts and views are the same ones built into the framework, only backed by a model for some additional capabilities. The problem I would like to address is that these template files are cached as soon as they are accessed on the public end, so it is not possible to see changes in the layouts or views unless the server is restarted. This does not occur in development mode where caching is disabled, but obviously turning off template caching in production wouldn't be great for performance. Clearing memcache doesn't seem to do the trick. Is it possible to programatically clear out the layouts and views cache in production, perhaps with something like reload! like we have in the console? Or am I stuck having to restart Passenger every time someone wants to tweak one of these layouts or views (perhaps using the approach in this thread: Rails Cache Clearing)?
Please note that I am not referring to clearing the page and action caches, which the public pages rely on and works just fine.
José Valim has a great chapter in "Crafting Rails Applications" that goes over this topic. Here is an approach that uses Mongoid to store view templates. If you build your own view Resolver, then you just need to call #clear_cache on the resolver instance when someone saves a new template in the database.
this configuration may help (at least it worked* for me):
config.action_view.cache_template_loading = false
works in rails 3
There's just a slight difference in rails 2:
config.action_view.cache_template_reloading = false
In production mode, it's normal to require a restart to implement rails code changes, which is what you are doing by editing the layouts and views. It sounds like you're really operating in a development environment if you are editing the application code while it's running. In production mode I don't know of a way to refresh Passenger without touching restart.txt or restarting the web server.
EDIT: You should be able to touch tmp/restart.txt programmatically from within your app. This should tell Passenger to reload on the next request.

Rails routing problem, action being skipped

I'm having a bizarre issue where it seems as if Rails is skipping the run of my particular Action. I have two environments that I am running this in. One (development) works fine and runs the action. The other (staging) is not running the action.
The error is that Rails can't find a template in the views directories for my given action, which is only supposed to respond with JSON (no template). I've done logging in the action and it just simply isn't being run. Rails immediately fails saying that the view doesn't exist.
Just to cover my bases, I've verified that the code is indeed the same, that my routes file is exactly the same, and that my rails version (3.0.1) is exactly the same between the two env's. Any help would be excellent here.
Apparently this comes in the department of facepalm. One of our developers had committed a new controller with a different file name but the same controller class name as another. It must be that in development rails was loading the new controller first, and so the old controller would override it and the issue was hidden. In stage however, it seems that the new controller was loaded last, which cannibalized our controller class and method, screwing everything up.
I'd be interested to know if others have encountered this problem in rails. May need to patch the controller loading code to always use the same sort mechanism (seems like file name would be most natural).

How can I prevent cache/cookies from affecting the path of ckeditor javascript files in a production rails app?

I have a built a rails app in which I am using the ckeditor 3.5.1 together with the ckeditor gem.
When running in development, everything works fine. But when I run in production, I get errors.Sometimes, the text_area with the ckeditor does not show up. But when I clear my cache and cookies, everything works fine. Then after a while, the error comes up again. The error comes up more often than not.
Closer investigation reveals that when the error occurs, some files like staging.domain.com/javascripts/ckeditor/config.js are instead being requested from staging.domain.com/posts/config.js which is naturally non-existent
(posts is from my Post model)
How can the cache/cookies affect which path the files are served from?
Does anyone know what else might be wrong and how I can fix it?
P.S. I am using Phusion passenger in production.
It would seem the problem was being cased by mod_pagespeed which was activated. By disabling it, everything came back to normal.
I am curious though, about how this was happening.

Resources