Devise with Omniauth for facebook authentication - ruby-on-rails-3

I am running ruby 1.9.2p18, Devise (1.3.4), Rails (3.0.4) and Omniauth (0.2.6).
Currently I have my webpage doing authentication with Devise, and it works fine.
I am trying to also add facebook authentication to it. I followed the instruction from https://github.com/plataformatec/devise/wiki/OmniAuth%3a-Overview .
When I do localhost:3000 I get
LoadError (no such file to load -- omniauth/core):
app/models/user.rb:3:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
config/routes.rb:6:in `block in <top (required)>'
config/routes.rb:1:in `<top (required)>'
and if refresh the page again sometimes I get
ActionController::RoutingError (No route matches "/")
I looked and under .rvm/gems/ruby-1.9.2-p180/gems/omniauth-0.2.6 I have the directory oa-core/ but not core/ .
I would really appreciate the help, I have no idea how to debug this one!

2 errors are different.
1. Error:
LoadError (no such file to load -- omniauth/core)
You need to add omniauth to your Gemfile and run 'bundle install'. If you've problem with it this Railscast might help:
Railscasts Omniauth 1
Also see 2 Devise videos on Railscasts.
2. Error:
ActionController::RoutingError (No route matches "/")
It says you haven't configured your app to have a main root. The main root is which matches "/".
- First choose which page you would like as landing page you or homepage. If you haven't created one then do it.
- Next you can find all named routes from shell by "rake routes".
- Then open config/routes.rb file and add main root by:
root :to => 'welcome#index'
substitute "welcome#index" with "your_chosen_controllers_name#chosen_method"
Don't add a named route created by Devise because it will end up with infinite loop ("stack level too deep" error).
Note that Devise wiki recommend no to use Devise if you've no prior experience with Rails. In this case I highly recommend to checkout Rails3.1 new has_secure_password? method.
HTH

Related

Replace 'alias_method_chain :save_attachments, :pasted_images' in Rails 5.2.3

I've got a Redmine 3.4.4 installation running, which uses Ruby 2.2.5-p319 and Rails 4.2.8. We want to upgrade this to Redmine latest (currently 4.0.4) which requires Rails 5.
I'm running the new server using 4.0.4 using Ruby 2.6.3-p62 and Rails 5.2.3. Overall it's OK, but we have a number of plugins installed we would like to migrate. Many of these have had problems because of deprecations in Rails 5. I've managed to muddle my way through 8 of 9 plugins, even though I've not written Ruby on Rails before, but I'm stuck on the last one and just can't figure it out.
The plugin is the My Page Customization plugin and when I attempt to migrate the database and plugins I get this error:
[centos#redmine]$ bundle exec rake db:migrate RAILS_ENV=production
rake aborted!
NoMethodError: undefined method `alias_method_chain' for ActivitiesController:Class
Did you mean? alias_method
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:11:in `block in included'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:7:in `class_eval'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:7:in `included'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/init.rb:30:in `include'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/init.rb:30:in `block (2 levels) in <top (required)>'
So, it's clear that the deprecated 'alias_method_chain' is the issue here. After some digging I found a lot of references online such as this one which is good and clear, but I just can't get code written that works - I keep getting syntax errors and can't figure out what I'm doing wrong.
This is the original snippet from activities_controller_patch.rb:
module ActivitiesControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
helper :issues
helper :queries
alias_method_chain :index, :esi
end
end
We'd like to hang onto this plugin if we can even though it doesn't officially support Redmine 4. I'm hoping someone with better Ruby knowledge will be able to help.
Instead of
alias_method_chain :index, :esi
you'll just use
alias_method :index_without_esi, :index
alias_method :index, :index_with_esi
It was some kind of syntactic sugar.

Comma gem export failing on Heroku - working on local environment

Using the the comma gem and exporting CSV files perfectly fine on my local environment. Also working on our staging environment which is running on an AWS instance.
ONLY failing on Heroku.
Heroku says:
2013-08-21T21:55:34.875724+00:00 app[web.1]: NoMethodError (undefined method `klass' for nil:NilClass):
2013-08-21T21:55:34.875724+00:00 app[web.1]: app/models/job.rb:220:in `block in <class:Job>'
2013-08-21T21:55:34.875724+00:00 app[web.1]: app/controllers/jobs_controller.rb:25:in `block (2 levels) in index'
2013-08-21T21:55:34.875724+00:00 app[web.1]: app/controllers/jobs_controller.rb:18:in `index'
And line 220 in my Job model is:
Comma do
...
customer :first_name
...
end
job.rb includes the line:
belongs_to :customer
And customer.rb has:
has_many :jobs
And as I mentioned this entire thing works great on my local box - I click the export button and out pops all the jobs, with each customer in the appropriate column.
For whatever reason it's only failing on Heroku.
I'm using Ruby 2.0.0-p0 on Heroku, Comma gem only verified up to 1.9.2 according to the documentation - BUT - I'm using Ruby 2.0.0-p0 on the staging server AND on my local environment and, again, it's working.
It's the 'klass" that's really throwing me off, because I don't have that anywhere in my code. I've read other threads about the same error and their solutions, but I don't have things like nested model forms and the like.
It is some issue with Heroku & Ruby 2.0 and associations? I've got the has_many and belongs_to on both sides, but still seems to be misunderstanding the association...
UPDATE
From the framework trace:
comma (3.1.0) lib/comma/extractors.rb:72:in `get_association_class' <====
comma (3.1.0) lib/comma/extractors.rb:55:in `block in method_missing'
comma (3.1.0) lib/comma/extractors.rb:48:in `each'
comma (3.1.0) lib/comma/extractors.rb:48:in `method_missing'
comma (3.1.0) lib/comma/extractors.rb:15:in `instance_eval'
comma (3.1.0) lib/comma/extractors.rb:15:in `results'
Your code may be the same on both local and prod, and it looks like you're using the same Rails/Ruby versions on local and production (good stuff!), but maybe your data isn't. Perhaps what's wrong is that in production you're retrieving a Job and navigating to some association, but that association doesn't exist, you're getting a nil, and kaboom?
It turned out that this was a legitimate bug in Comma gem - https://github.com/comma-csv/comma/releases
I reported and they accepted, fixed, and released v 3.1.1

Rails Tutorial - weird RSpec behavior

I'm currently in section 10.3.2 of the Rails Tutorial (beta) and ran into some problems with RSpec.
rspec spec/ runs perfectly, however if I do rspec spec/requests/micropost_pages_spec.rb as described in the tutorial I get the following error:
Failures:
1) Micropost pages micropost creation with invalid information should not create a micropost
Failure/Error: before { visit root_path }
ActionView::Template::Error:
undefined method `model_name' for NilClass:Class
# ./app/views/shared/_micropost_form.html.erb:1:in `_app_views_shared__micropost_form_html_erb__567210303736562711_70234980477780'
# ./app/views/static_pages/home.html.erb:8:in `_app_views_static_pages_home_html_erb___61006871036382679_70234970424160'
# ./spec/requests/micropost_pages_spec.rb:11:in `block (3 levels) in <top (required)>'
Performing the test manually in the web browser seems to work perfectly as well.
Not sure if I did something wrong or if there's a "bug" in the tutorial. Can anyone give a hint?
UPDATE 1: Here's a link to the whole project on GitHub.
UPDATE 2: I now found out that when I restart the rails server I get the error, too, when I hit the page the first time. But when I load the page a second time (reload) then it works perfectly.
Found the problem. Rather stupid mistake. In my static_pages_controller.rb I had
def home
def home
#micropost = current_user.microposts.build if signed_in?
end
end
Thanks anyway for the tips.

Guard w/ RSpec2, Ruby1.9.3, Rails 3.1.3

I am running Guard successfully with notifications provided by Libnotify.
funkdified#funkdified-laptop:~/railsprojects/sample_app$ guard
Guard uses Libnotify to send notifications.
Guard is now watching at '/home/funkdified/railsprojects/sample_app'
Guard::RSpec is running, with RSpec 2!
Running all specs
...
Finished in 0.06053 seconds
3 examples, 0 failures
If I modify the spec file I am alerted as to the results of the test, both in the terminal and with a popup notification. If I modify a controller file, again tests run normally. However, when I modify routes.rb, the whole things falls on its face and Guard stops working normally and throws up an error. Anyone have any ideas?
Error:
Running: spec/routing
/home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load': cannot load such file -- /home/funkdified/railsprojects/sample_app/spec/routing (LoadError)
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun
Forgot to mention, if I kill Guard and restart (after making changes to routes.rb) then Guard again performs normally, suggesting that a test has now failed:
funkdified#funkdified-laptop:~/railsprojects/sample_app$ guard
Guard uses Libnotify to send notifications.
Guard is now watching at '/home/funkdified/railsprojects/sample_app'
Guard::RSpec is running, with RSpec 2!
Running all specs
..F
Failures:
1) PagesController GET 'about' returns http success
Failure/Error: get 'about'
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>"about"}
# ./spec/controllers/pages_controller_spec.rb:22:in `block (3 levels) in <top (required)>'
Finished in 0.0576 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:21 # PagesController GET 'about' returns http success
Check your spec directory. It should have a routing sub-directory for routing specs. If not, just create an empty one. Apparently, RSpec does not create any sub-directories under spec when running rails g rspec:install, but guard expects it to be there.
I think you may have the following line in your Guardfile:
watch('config/routes.rb') { "spec/routing" }
If you don't have specs in spec/routing, then don't folder that you don't need. Change the line to:
watch('config/routes.rb') { "spec" }
Now, all your specs will run when you update your routes.rb file.

Rails app error after updating OS

I updated my system to opensuse 11.4 and set up Ruby 1.9.2 via RVM. I reinstalled all the gems and updated bundle all without issue.
The problem is the vague error I get when running the app:
ActionController::RoutingError (undefined method `sub' for nil:NilClass):
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/news_controller.rb:1:in `<top (required)>'
I don't even know where to start looking for the problem. Both files on line 1 is the class declaration. ie class NewsController < ApplicationController and class ApplicationController < ActionController::Base. Neither files have a method call to 'sub' and no other information is given.
The app worked perfectly before the upgrade (which was using Rails 3.0.5 also) so I think the issue is somewhere in Rails, except running a new application with a simple scaffold has no problems. news#index is root in the routes file, but changing root to something else does nothing.
EDIT:
resources :categories,:addresses,:calendars,:topics,:profile,:news,:account_setting
resources :boards do
member do
get :move
post :move_category
end
end
get "user/index"
get 'login/index'
get 'login/new'
post 'login/create'
post 'login/authenticate'
get 'login/forgot_password'
put 'login/reset_password'
root :to => "news#index"
No need to do all that. I think the solution was probably a lot simpler. I just got the same error. Turns out I just had a misnamed helper module:
module AssetHelper
...
end
Should've been
module AssetsHelper
...
end
I got it resolved, although I don't know what caused it.
I created a new app and copied over app, routes, db, lib, and public and the problem disappeared.