Can't work out what I've done to mess this up. It works on localhost but not when I deploy any more. I have migrated the database and restarted heroku but it's still not working.
My heroku log is
NoMethodError (undefined method `current_user=' for #<Class:0x000000044ac488>)
current_user is referenced many times the app and has previously worked fine. And this is the same error when trying to load many different pages. It's not pointing me to a particular action...
This happened to me because I accidentally removed the devise route:
devise_for :users, controllers: {registrations: "registrations"}
end
Related
My apps work fine in development mode on my localhost. But when i deploy my apps to Heroku i have an error like this :
/app/app/controllers/api/v1/Associations/associations_controller.rb:1:in `<top (required)>': uninitialized constant Api::V1::Associations (NameError)
I dont know whats wrong with my code. In my controller i have defined the class name like below :
class Api::V1::Associations::AssociationsController < Api::V1::ApiController
I already put this code on my application.rb but still no luck:
config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
I have routes like below :
namespace :api do
namespace :v1, :defaults => {:format => :json} do
namespace :associations do
get "/index" => "associations#index"
post "/create" => "associations#create"
post "/join" => "associations#join"
resources :associations_groups
resources :group_joined_by_springs
resources :group_created_by_springs
end
end
end
Everything works fine in my local using development mode. I cannot figure out how to solve this errors. I hope someone could help me.
P/s : I already looked all the solution provided on this site.
Edit (Rake routes)
Below is my routes for Associations
api_v1_associations_index GET /api/v1/associations/index(.:format) api/v1/associations/associations#index {:format=>:json}
api_v1_associations_create POST /api/v1/associations/create(.:format) api/v1/associations/associations#create {:format=>:json}
api_v1_associations_join POST /api/v1/associations/join(.:format) api/v1/associations/associations#join {:format=>:json}
move your api directory in to the app directory and remove this setting from application.rb - config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
All subdirectories of app in the application and engines present at boot time. For example, app/controllers. They do not need to be the default ones, any custom directories like app/workers belong automatically to autoload_paths.
From http://guides.rubyonrails.org
in rails development environment I find a user by its lowercased username in the routes.
For example:
#user = User.find_by_username(params[:id].downcase)
This piece of code runs perfectly fine in development, but when this code runs in production (Heroku) I get
ActionView::Template::Error (undefined method `username' for nil:NilClass):
Is there a go around for this issue?
By the end I've used
User.where('lower(username) = ?', params[:id]).first
Sorry for the consfusion and the incertitude :)
I am new to the rails programming.
I had a one problem to building a first rails application in rails version 2.3.14.
The problem is , I am not able to add the root in the config/routes.rb file.
I was created the home and about pages. I am trying to add the home page as a root. For that I was added the below line in the routes.rb file.
root 'pages#home'
But it gives error. The error is,
undefined method `root' for main:Object (NoMethodError)
It says the root is a undefined method. So, What method is used to add the home page as a root in rails version 2.3.14.
Use map.root and start upgrading your app to newer version of Rails :)
map.root :controller => "pages", :action => "home"
I have a definition in routes.rb that is something like this:
namespace :admin do
resources :users do
resources :email_addresses, controller: 'email_addresses'
end
end
The two controllers that exist are Admin::UsersController and EmailAddressesController. The problem I'm seeing is that once I deploy the app to production, trying to access any of the links for the email addresses resource results in a 404 and an uninitialized constant error for Admin::EmailAddressesController. For whatever reason, this isn't happening in my development environment.
Here's the output from my production environment log:
Started GET "/admin/users/3/email_addresses/new" for 192.168.206.6 at 2013-08-21 10:00:43 -0700
ActionController::RoutingError (uninitialized constant Admin::EmailAddressesController):
Here it is in my development environment working just fine:
Started GET "/admin/users/1/email_addresses/new" for 127.0.0.1 at 2013-08-21 10:03:04 -0700
Processing by EmailAddressesController#new as JS
Strange, right?
Here is an example of the link that I'm using that results in an error (once clicked):
link_to "Add Email Address", new_admin_user_email_address_path(user)
UPDATE: It seems as though the issue may be related to the issue mentioned in this bug report: https://github.com/rails/rails/issues/5798 . Question is, how do I explicitly reference the non-namespaced controller in controller: ?
I have the following in my routes.rb file for Rails 3:
13 namespace :user do
14 root :to => "users#profile"
15 end
I get this error on heroku:
ActionController::RoutingError (uninitialized constant User::UsersController):
I already restarted the application.
I am doing this because I am using devise and this is what it says on the wiki:
https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in
The problem is that Rails is expecting there to be a controller within a module called Users because that's what namespace :user infers. Perhaps you meant to use scope instead of namespace?
scope :path => "user" do
root :to => "users#profile"
end
Note: in this situation if you've only got one route it would not be wise to use scope, but if you've got multiple ones with the /user prefix then it would be fine to. If you only had one, I would do this instead:
get '/user', :to => "users#profile"
Heroku environments run in production mode. When you run locally, you run in development mode, which accounts for at least one difference. Try this instead:
RAILS_ENV=production bundle exec rails s
and see if you notice the same error.