I have the following controller
class ActiveUsersController < ApplicationController
def edit
end
end
And my routes.rb is like this:
map.resources :active_users
When I try to access the controller using the url http://localhost:3000/active_users/COo8e45RqQAHr6CqSCoI/edit I got the following error:
NameError in Active usersController#edit
uninitialized constant ActiveUsersController
RAILS_ROOT: /Users/vintem/Documents/Projetos/Pessoal/bugfreela
Application Trace | Framework Trace | Full Trace
/Users/vintem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/Users/vintem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
/Users/vintem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
/Users/vintem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:361:in `constantize'
/Users/vintem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in `each'
/Users/vintem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in `constantize'
/Users/vintem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
/Users/vintem/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:443:in `recognize'
/Users/vintem/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:436:in `call'
Can anyone help me?
Thanks
resources refers to the model and an assumed correlate controller named similarly. Do you have an ActiveUser model class? Or is it something else, say User? E.g.:
map.resources users, :controller => "active_users"
Check out the API docs:
http://api.rubyonrails.org/classes/ActionController/Resources.html
Hard to tell exactly what's wrong from the info you've provided.
Related
Rails 4.2.4, Ruby 2.1.7
I have a module inside lib/ directory.
lib/BLL/user_feed.rb
module BLL
class UserFeed
def initialize
logger.debug "Class has been initialized"
end
def get_user_feed(user_id)
# logic here
return {
# object
}
end
end
end
When I try to include that in my controller to use my user_Feed logic,
class UserfeedController < ApplicationController
include BLL
before_action :authenticate_user!
def show
# some logic
end
end
In my config/application.rb
config.autoload_paths << Rails.root.join('lib')
This runs fine locally, however, it breaks when I deploy it on Heroku.
it's throwing
ActionController::RoutingError (uninitialized constant UserfeedController::BLL):
error.
2015-10-20T13:45:13.791457+00:00 app[web.1]: /app/app/controllers/api/v1/userfeed_controller.rb:1:in `<top (required)>': uninitialized constant Bll (NameError)
2015-10-20T13:45:13.791457+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!'
2015-10-20T13:45:13.791458+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/engine.rb:471:in `each'
2015-10-20T13:45:13.791459+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/engine.rb:471:in `block in eager_load!'
2015-10-20T13:45:13.791460+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/engine.rb:469:in `each'
2015-10-20T13:45:13.791462+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/engine.rb:469:in `eager_load!'
2015-10-20T13:45:13.791463+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/engine.rb:346:in `eager_load!'
Any suggestions?
I think you're missing a module BLL; end in lib/bll.rb
But also, play with naming the module Bll, but I don't think that's it
try
config.autoload_paths += %W(#{config.root}/lib/BLL)
and dont forget to restart the server
Edit1
Moreover; changing the name of Dir BLL to bll also works
Ruby defaults to CamelCase, you'll have to use the following:
#vendor/bll/user_feed.rb
module Bll
class UserFeed
...
end
end
As a second, the vendor dir is autoloaded (to the best of my knowledge), so the above code should work to fix the UnrecognizedConstant error.
https://softwareengineering.stackexchange.com/questions/123305/what-is-the-difference-between-the-lib-and-vendor-folders
Rails in fact loads your app directory when the app loads. So actually no need to mention your app/bll in autoload paths.
However, what I am doing wrong here in this case is adding module on top of the class.
So, my app is looking for app/bll/bll/Whatever
module Bll - there is not need for this module to be declared
class Whatever
# some logic.
end
end
All you need to do is.
class Whatever
end
After this, your class is available to use.
I am trying to get basic authentication working using devise and mongomapper.
Following the instructions here:
http://johnwyles.com/2010/03/15/sessions-in-mongodb-using-mongomapper-and-devise/
(except deferring the routes.rb changes until after the generators are run to address errors)
I got it as far as getting the following paths to work:
/users/sign_up ::
/users/sign_in ::
/users/password/new ::
/users/confirmation/new
However, just trying to hit "/" gives me an error
NameError in UserController#sign_in
uninitialized constant UserController
RAILS_ROOT: /Users/bentrevino/Documents/Dev/devisetest
Application Trace | Framework Trace | Full Trace
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:364:in `constantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:363:in `each'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:363:in `constantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/routing/route_set.rb:444:in `recognize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/routing/route_set.rb:437:in `call'
After I submit a sign-up request, I get this error
RuntimeError in Registrations#create
Showing /Library/Ruby/Gems/1.8/gems/devise-1.0.8/app/views/devise_mailer/confirmation_instructions.html.erb where line #5 raised:
Missing host to link to! Please provide :host parameter or set default_url_options[:host]
Extracted source (around line #5):
2:
3: <p>You can confirm your account through the link below:</p>
4:
5: <p><%= link_to 'Confirm my account', confirmation_url(#resource, :confirmation_token => #resource.confirmation_token) %></p>
Does anybody know what might be going on here?
Thanks!
Ben....
At least one issue you are having is that you have not created a controller for your root route that you specified in config/routes.rb file. Run a call to rails generate controller [name] to make a new controller. Then specify that name in your config/routes.rb file for our root route.
I am running RVM (Ruby 1.8.7-head, Rails 2.3.8) and have the BASICS of a new app running. I have Authlogic working, with the minimal code to make that work. I am attempting to use ACL9 (which I have working on a different project, same RVM gemset)
class User < ActiveRecord::Base
# authentication
acts_as_authentic
# authorization
acts_as_authorization_subject
def full_name
"#{self.first_name} #{self.last_name}"
end
end
When I attempt to just run a simple check to make sure ACL9 is working properly...
script/console
u = User.first
u.has_role?(:anyrole)
I get this error...
ruby-1.8.7-head > u.has_role?(:anyrole)
NameError: uninitialized constant User::Role
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:105:in `const_missing'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/base.rb:1:in `compute_type'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activesupport-2.3.8/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/base.rb:2230:in `compute_type'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/reflection.rb:156:in `send'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/reflection.rb:156:in `klass'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/reflection.rb:187:in `quoted_table_name'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations/has_and_belongs_to_many_association.rb:102:in `construct_sql'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:21:in `initialize'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations/has_and_belongs_to_many_association.rb:5:in `initialize'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations.rb:1306:in `new'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations.rb:1306:in `role_objects'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/acl9-0.12.0/lib/acl9/model_extensions/for_subject.rb:39:in `has_role?'
from (irb):2
I'm not sure why this works with every other app I have, but not this one - and I'm not sure what the error message is saying.. any help is appreciated.
class Role < ActiveRecord::Base
acts_as_authorization_role
end
I'm trying to use some validation only if a specific method in my controller is being called:
validates_presence_of :reasons, :on => :update_description
However I get this error:
TypeError in RegistrationsController#create
nil is not a symbol
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:586:in `send'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:586:in `validates_presence_of'
/Users/blah/Desktop/testApp/app/models/registration.rb:6
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:380:in `load_without_new_constant_marking'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:380:in `load_file'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:379:in `load_file'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:259:in `require_or_load'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:425:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:437:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:96:in `const_missing'
/Users/blah/Desktop/testApp/app/controllers/registrations_controller.rb:81:in `create'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1331:in `send'
Am I going about this the wrong way? Basically I have a multi-page form and I've broken up the pages into multiple update methods which they submit. In this case I'm updating the registration object using a method I've defined called update_description. I only want the validation to occur when this method is called. Possible?
Update:
Adding error line:
def create
#registration = Registration.new(params[:registration]) //error is here
[nav logic]
end
The :on parameter specifies when this validation is active (default is :save, other options :create, :update). This is relative to the model, not the controller.
It looks like you want a wizard plugin. The two that I know of are:
acts_as_wizard
wizardly
Hopefully these should get you started.
I update my rails application 2.0.2 to 2.3.5. I use active scaffold for the administration part.
I change nothing in my code but a problem is coming with the update.
I have a controller 'admin/user_controller' to manage users.
Here is the code of the controller:
class Admin::UserController < ApplicationController
layout 'admin'
active_scaffold :user do |config|
config.columns.exclude :content, :historique_content, :user_has_objet, :user_has_arme, :user_has_entrainement, :user_has_mission, :mp, :pvp, :user_salt, :tchat, :notoriete_by_pvp, :invitation
config.list.columns = [:user_login, :user_niveau, :user_mail, :user_bloc, :user_valide, :group_id] #:user_description, :race, :group, :user_lastvisited, :user_nextaction, :user_combats_gagner, :user_combats_perdu, :user_combats_nul, :user_password, :user_salt, :user_combats, :user_experience, :user_mana, :user_vie
config.create.link.page = true
config.update.link.page = true
config.create.columns.add :password, :password_confirmation
config.update.columns.add :password, :password_confirmation
config.create.columns.exclude :user_password, :user_salt
config.update.columns.exclude :user_password, :user_salt
config.list.sorting = {:user_login => 'ASC'}
config.subform.columns = []
end
end
This code hasn't change with the update, but when I go in this page, I got this error:
uninitialized constant Users
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:361:in `constantize'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in `each'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in `constantize'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb:28:in `reverse_matches_for'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb:24:in `each'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb:24:in `reverse_matches_for'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb:11:in `reverse'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb:117:in `autolink?'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold.rb:107:in `links_for_associations'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/columns.rb:62:in `each'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/columns.rb:62:in `each'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold.rb:106:in `links_for_associations'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold.rb:59:in `active_scaffold'
/Users/Kiva/Documents/Projet-rpg/jeu/app/controllers/admin/user_controller.rb:11
I search since 2 days but I don't find the problem, can you help me please.
the naming convention in your application seems buggy
it should be:
class Admin::UsersController < ApplicationController
not UserController as it is. maybe it won't fix your problem, but it worth a try!
It seems to be a problem with the way the Model is defined. I had the very same issue when accessing tables in the database with a rake backup task. The problem was that I had a table defined in the database through "belongs_to". I didn't think I needed a model for that table but constantize kept failing. Introducing the model fixed the problem.
Table : users_clients
Model : UsersClient
Starting with Rails 2.3.x you have to install the Render Component plugin:
./script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3
See instructions here: https://github.com/activescaffold/active_scaffold/wiki/getting-started