New rails 4.1 mailer preview action not found error - ruby-on-rails-4

Rails has 607 open issues...so, rather than plugging that hole even more I though Id try here first. I have upgraded to 4.1 and am implementing rails mailer previews. I tried upgrading my existing mailer and adding tests/mailers/previews directory. When that gave the following error I tried generating a new mailer. Same error.
class NotifierPreview < ActionMailer::Preview
def welcome
Notifier.welcome(User.first)
end
end
results in this error:
The action 'notifier' could not be found for Rails::MailersController
I've tried searching google, the docs, stack overflow, but nothing eludes to this error.
Anyone experience this or have any ideas?

The default preview path is /test/mailers/previews but rspec will override this to be /spec/mailers/previews
You can set the path to be whatever you like with:
config.action_mailer.preview_path = "#{Rails.root}/test/mailers/previews"

This is because you are using UserMailer with NotifierPreview. Change NotifierPreview to UserMailerPreview and it will start working. Check the example implementation https://github.com/RichIsOnRails/ActionMailerPreviewsExample and tutorial.
Cheers!!

If you're using rspec, make sure that the rspec-rails gem is being loaded in the development environment, otherwise Rails will look for the previews under the /test folder, not /spec.

Remove the line(s)
get '/:controller(/:action(/:id))'
get '/:controller(/:action(/:id))(.:format)'
from your routes.rb
As #hellion says in a comment on the previous answer this is the solution to this problem.

Related

rails server won't start because ActiveAdmin Comment change

I'm trying to start a rails app (4.1.8), using activeadmin version from gregbell/activeadmin in my Gemfile. On startup rails first complained "config.allow_comments is no longer provided in ActiveAdmin 1.x. Use config.comments instead. (RuntimeError)" So I changed to config.comments in active_admin.rb, tried to restart and now I get:
You're trying to register ActiveAdmin::Comment as Comment, but the existing ActiveAdmin::Resource config was built for Comment! (ActiveAdmin::ResourceCollection::ConfigMismatch)
What gives, anyone see this before and know how to fix it? Seems like there's no change in active_admin and now suddenly this.
Many Thanks for any advice.
UPDATE:
For anyone with the same issue, I solved it by changing the activeadmin Comment class like this:
change
ActiveAdmin.register Comment do
to this
ActiveAdmin.register Comment, as: "UserComment" do
as mentioned in the comments here: https://github.com/activeadmin/activeadmin/issues/301
...posting my own answer to this question... I had to change the signature of the activeadmin Comment class as mentioned in my update above. It came from the comments here: https://github.com/activeadmin/activeadmin/issues/301

How to auto-reload changes in a Rails Engine?

I have a Rails 4.1.0 mountable engine. In the engine's application_helper.rb:
module MyEngine
module ApplicationHelper
def test123
"test123"
end
end
end
The method is in the dummy app's view general/index.html.erb view:
%<= test123 %>
This works. However, when I change the string returned by def test123 and refresh the browser, the new string is not displayed.
Of course, restarting the web server in the dummy app shows the new string.
So the question is, how to reload the engine's files without having to restart the web server?
PS. I am preferably looking for a way to do this using Rails itself, or a specific gem that solves this problem (but not the generic gems like Guard, Spork etc. although if all else fails, I will consider those too.)
PPS. There are similar questions on SO, but I have tried them all (even though they are for Rails 2.x, 3.x), and they have not worked for me.
You should explicitly require dependent helpers:
# engines/my_engine/app/controllers/my_engine/application_controller.rb
require_dependency "my_engine/application_helper" # This is a key point!
module MyEngine
class ApplicationController < ::ApplicationController
helper ApplicationHelper
...
you can use some thing like zeus which is helping a lot in watching project files for changes except in some cases when you change the configuration files it doesn't work and needs to be manually restarted.
but overall in most cases this works more than awesome

Some cookie makes Play! answer with an err_empty_response

I have a JS plugin (getvero.com) that creates a cookie like that
[{"command":["events_track","Visited site",{},{"time":1377020238096}],"job_id":"1377020238097_9041"},{"command":["events_track","Visited Site",{"URL":"http://mywebsite.com/discoveries/","Referrer":"Direct","_n":"Visited Site","_k":"cd4dde369919a1626d13a28d1d54bc11bdc7f48d","_p":"qLipS0SbtoTOfJCUyiyRjoCQFFo=","_t":1377020242},{"time":1377020241741}],"job_id":"1377020241741_235"},{"command":["events_track","Visit all discoveries",{"_n":"Visit all discoveries","_k":"cd4dde369919a1626d13a28d1d54bc11bdc7f48d","_p":"qLipS0SbtoTOfJCUyiyRjoCQFFo=","_t":1377020242},{"time":1377020241752}],"job_id":"1377020241752_8389"}]
which makes play answer an err_empty_response when I ask for a page without removing the cookie.
I was with play 2.0.4, I upgraded to 2.0.6 but didn't make it work.
Seems close to this issue : http://play.lighthouseapp.com/projects/57987/tickets/1618-long-cookies-with-double-quote-values-make-play-fail-before-the-request-is-handled
I'll try 2.1 later.
Otherwise, any idea ?
Upgrading to Play 2.1 made it work.

Using multiple jQuery versions problem

I am building control that uses last version of jstree. Problem is that whole system is build using jQuery 1.3.2, but i need to use jQuery 1.4.2 for jstree, also to prevent errors need "$" still pointing to jQuery 1.3.2 to make system works normally. I tried to solve problem like this
var jq142 = jQuery.noConflict(true);
And it works, but when i added other control to form like "datepicker" that initialized via $("#id").datepicker it throws error $("#id").datepicker is not a function
When i inspect DOM variables through firebug all is ok - $ is pointing to 1.3.2 and datepicker function is registered.
What it can be?
Thanks
in case anyone came to this by looking for unanswered questions, the answer was to simply upgrade to 1.4.*
btw: jQuery 1.7 has just been released... time to upgrade again ;-)

Unit test with Authlogic on Rails 3

I would like to write some unit test with a logged user using Authlogic. To start right, I used some code hosted in http://github.com/binarylogic/authlogic_example. But I get an error after rake test, because of "test_helper.rb" and the following class:
class ActionController::TestCase
setup :activate_authlogic
end
Here is my error:
NameError: undefined local variable or
method `activate_authlogic' for
I think this Authlogic example is mapped over Rails 2; maybe it's a little bit different on Rails 3. Is there an other example where I can take example about unit test?
Many thanks.
Do you require 'authlogic/test_case' and include Authlogic::TestCase?
I had a similar issue (using rspec, though) and read through the code at http://github.com/trevmex/authlogic_rails3_example
As of Rails 3.1 and Authlogic 3.0.3, the only thing I've had to add to activate authlogic was
features/support/env.rb
Before do
activate_authlogic
end
I don't realize where to put include Authlogic::TestCase, so I put this after the requires in spec_helper.rb and it worked. There is a better place for it?