NameError for ActionMailer within ActionController - ruby-on-rails

I'm on Rails 3.0, and I pretty much followed the steps on the API to define a mailer by doing
rails generate mailer Notifier
Within my controller, I call Notifier.mytemplate(...)
When I go to the page, I see an error:
uninitialized constant MyController::Notifier
Seems like something is not getting initialized correctly, and it's not realizing that Notifier is already defined in app/mailers/notifier.rb

Related

How can I find a definition true_user for Rails app using devise gem?

After Rails 5.2 and ruby 2.6.5 upgrade, I am getting errors: (1) NameError: uninitialized constant UserUploader::Uploader and (2) ArgumentError undefined class/module UserUploader::Uploader when calling true_user within app/controllers/application_controller.rb.
Where can I find a definition of method true_user (I couldn't find any source for this method in the web)?
I am not seeing the relationship with true_user call and class UserUploader < ImageUploader.

Rails Console 'helper' and 'app' Appear Incomplete

Using ruby 2.3.0 and rails 4.2.5.1, I'm trying to figure some things
out using the rails console. I have several instances where app or helper seem like they have a method I want, but I often end up with the NoMethodError message. This happens even in a brand-new application where I've edited nothing and given no special options to the rails new command. For instance:
irb(main):015:0* helper.timez
... here I hit TAB to get:
irb(main):015:0* helper.timezone
... and hit ENTER, only to find:
NoMethodError: undefined method `timezone' for #<ActionView::Base:0xc662b80>
Why would tab-expansion in the console expand to methods that don't
exist? More importantly, if they're supposed to be there, why aren't
they? What can I be doing wrong?

Extending ActiveRecord in rails 4.2

I've followed this guide:
http://guides.rubyonrails.org/plugins.html#add-an-acts-as-method-to-active-record
In fact, I've actually copied the code and put into my app and it doesn't work.
I keep getting undefined method errors.
When I use console, I can check if the module is initialized and it is, but the model that uses the "acts_as" method throws undefined method errors.
Also in console I can call ActiveRecord::Base.send :include, ... explicitly and then it includes the module -- then everything works. But try as I may, I can't get rails to call .send on ActiveRecord::Base at load time.
Any ideas?

Can't create users in rails when using authlogic because of cookies

So, I have a standard rails 3 app with authlogic. If I'm not in the browser (in the console or in the test environment), I can't create user models.
For example:
I have this code either in a rspec test or in my console:
user = User.create(...user attributes...)
And I get this error:
NoMethodError: undefined method `cookies' for main:Object
I've looked all over the internet and can't figure this out. Any help would be greatly appreciated.
EDIT:
So, I looked around some more and found in the documentation to do this:
include Authlogic::TestCase
but then I get this error:
uninitialized constant Authlogic::TestCase
I had this same exact problem. Where in your application did you put the following line:
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
I ran into this error when I placed the line in either the environment.rb file or within a file within my initializer folder.
I eliminated the problem when I placed the line in my ApplicationController instead.

Where's ActionController::Dispatcher in Rails 3.2?

I'm following an example in The Rails 3 way, and when I tried to send a request to dispatcher in the console, with ActionController::Dispatcher.new.call(env).last.body
I got
1.9.3p194 :001 > ActionController::Dispatcher.new.call(env).last.body
NameError: uninitialized constant ActionController::Dispatcher'
I was using rails 3.2.6, I checked the rails api and found out they removed dispatcher in the ActionController, but the rails guide said:ActionController::Dispatcher.new is the primary Rack application object of a Rails application. Any Rack compliant web server should be using ActionController::Dispatcher.new object to serve a Rails application.
I find the v3.0.7 of rails api, the Dispatcher still exist in that version.
So, here are my questions: how can I find the equivalent methods serve as ActionController.Dispatcher.new? and given that my apps work well with rails 3.2.6, which part of rails plays the role as ActionController.Dispatcher now?
This is what the Rails edge guides say about primary Rack application objects:
ApplicationName::Application is the primary Rack application object of a Rails application. Any Rack compliant web server should be using ApplicationName::Application object to serve a Rails application.
So ActionController::Dispatcher.new has just been replaced by ApplicationName::Application. I'm not sure when they made this switch. This worked for me:
Blog::Application.call(env).last.body
(The first few lines after NoMethodError: undefined method 'key?' for nil:NilClass tell us that the key? method is being called in actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb. Working backwards from there, we can see that the variable
params = env['action_dispatch.request.path_parameters']
is nil when it shouldn't be. So we can set env['action_dispatch.request.path_parameters'] in the console, but that leads to another NoMethodError on a nil object set in the initialize method. So we could probably fix that by passing in an options hash to Dispatcher.new, but it's probably best just to use ApplicationName::Application.)
It has been moved to ActionDispatch (actionpack/lib/action_dispatch) and can be found here: actionpack/lib/action_dispatch/routing/route_set.rb, class called
ActionController::Routing::RouteSet::Dispatcher.new

Resources