NoMethodError in Devise/registrations#new - ruby-on-rails

I have Rails 3.2.1 and try to install devise (1.1.rc0) with ubuntu
My rake routes give me
new GET /users/registration/sign_up(.:format) devise/registrations#new
config/routes.rb
DeviseApp::Application.routes.draw do
devise_for :users
match "users/registration/sign_up" => "devise/registrations#new"
resources :projects
root :to => "home#index"
end
when http://127.0.0.1:3000/users/registration/sign_up
I take
undefined method `user_registration_path' for Class
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.1'
gem 'sqlite3'
gem 'devise', '1.1.rc0'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
I follow instructions from episode 209 Introducing Devise Railscasts.

You have to define the route as a named route if you want to use user_registration_path
match "users/registration/sign_up" => "devise/registrations#new", :as => 'user_registration'

The final solution was to change the Gemfile. New Gemfile:
gem 'rails', '3.0.11'
gem 'sqlite3', '1.3.3'
gem 'devise'
gem 'recaptcha', :require => 'recaptcha/rails'
Maybe the combination rails '3.2.1' and devise '1.1.rc0' was catastrophic for me.

Related

wrong number of arguments (2 for 0..1) at redirect_to

Error image
argument error
home_controller.rb
class HomeController < ApplicationController
def home
#activities = Activity.order("created_at DESC").page(params[:page]).per_page(5)
end
def login
render
end
def logout
session[:school_id] = nil
session[:parent_id] = nil
session[:user_id] = nil
redirect_to :controller => 'home', :action => 'login'
end
Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.4'
gem 'mysql2', '~> 0.3.20'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'remotipart', '~> 1.2'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bootstrap-sass', '~> 3.3.5'
gem 'sass-rails', '~> 5.0'
gem 'bootstrap_form'
gem 'devise', '~> 3.5', '>= 3.5.2'
gem 'bartt-ssl_requirement', '~>1.4.0', :require => 'ssl_requirement'
gem 'will_paginate'
gem 'paperclip'
gem 'bcrypt', '~> 3.1.7'
group :development, :test do
console
gem 'byebug'
end
redirect_to :controller => 'home', :action => 'login'
This is not correct, not to mention ugly. Instead, create a route in routes.rb that does that action. For example:
get 'login' => 'home#login'
Then you would use:
redirect_to login_path
BONUS
****You should read up on rails routing to make better routes too.****
Also, a home controller that handles logins does not seem very clean.
A better route would be something like the following but it requires different controller setup:
resources :sessions
which creates the following route and many others(not exactly but lets ignore the details):
get 'login' => 'sessions#new'
Again, I recommend you read up on Rails routing.
Just to explain the redirect_to actually expects a path not controller or action and Helsing has answered it very beautifully that how can you make a route out of controller and its action.
It looks to me that you may have had your code written incorrectly initially, and even though you've fixed the source code, Rails is still using the old (incorrect) version.
You must have had some variant of:
redirect_to 'home', :action => 'login'
redirect_to 'home', 'login'
before.
Leave your code the way you have it (redirect_to(:controller => 'home', :action => 'login')), and make sure you restart your Rails process correctly.

RefineryCMS: routing error introduced by portfolio gallery plugin

I'm using RefineryCMS as a rails CMS, it was working like a charm until I followed the answer in this question to get a simple image gallery functionality going. Now I'm getting the same error as shown on this issue. I didn't change any of my rails code to introduce a link_to tag with a nil reference, however (there is a link_to image_tag line in the guide but I've commented that out and nothing changed), so it's happening in the autogenerated code I believe. Here's the full error I get when I login to refinery on my site:
ActionController::UrlGenerationError in Refinery::Authentication::Devise::Admin::Users#index
Showing /home/mpvoss/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/bundler/gems/refinerycms-0a37f8090278/core/app/views/refinery/admin/_menu_item.html.erb where line #1 raised:
No route matches {:action=>"index", :controller=>"refinery/refinery/portfolio/admin/galleries", :locale=>:en}
Extracted source (around line #46):
44 message << " missing required keys: #{missing_keys.sort.inspect}" unless missing_keys.empty?
45
46 raise ActionController::UrlGenerationError, message
47 end
48
49 def clear
Trace of template inclusion: /home/mpvoss/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/bundler/gems/refinerycms-0a37f8090278/core/app/views/refinery/admin/_menu.html.erb, /home/mpvoss/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/bundler/gems/refinerycms-0a37f8090278/core/app/views/layouts/refinery/admin.html.erb
Note: Just loading the website without logging into refinery works because it's not trying to load the menu code below that encounters the routing issue.
Okay, let's have a look at _menu.html.erb
<%= link_to menu_item.title, refinery.url_for(menu_item.url),
:class => ("active" if menu_item.highlighted?(params)),
:id => "plugin_#{menu_item.name}" %>
This code just makes a menu bar for all the plugins. It can be commented out and refinery works (the error above goes away), but I need that menu bar to make changes to the website.
What I've tried.
I found a galleries_controller.rb in ~/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/bundler/gems/refinerycms-portfolio-289b85b18771/app/controllers/refinery/portfolio/admin, which seems to be the controller the error was talking about. It didn't have an index action, so I added an empty action to see if that was the problem and nothing changed. The routes.rb for the ~/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/bundler/gems/refinerycms-portfolio-289b85b18771/ gem is below
Commenting out the portfolio gem in my Gemfile and running bundle install but I get the same error because the autogenerated code (referring to stuff like .rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/bundler/gems/refinerycms-0a37f8090278/) is still getting executed (I use git for version control and make a clean clone of the project before these changes and it has the same problem because the autogenerated code is not part of the version control).
gem uninstall of the refinery-photo-gallery, refinerycms-page-images and refinerycms-portfolio gems I thought might be causing the problem
I moved all the gems in ~/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/bundler/gems/ out of that directory to see if a bundle install would regenerate fresh, clean gems but nothing changed.
None of these ideas has made a difference. If any clarification is needed please just let me know. I've been stumped on this for a week and my Googling skills are failing me. Any help is really appreciated!
~/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/bundler/gems/refinerycms-portfolio-289b85b18771/routes.rb
Refinery::Core::Engine.routes.draw do
# Frontend routes
namespace :portfolio, :path => Refinery::Portfolio.page_url do
root :to => "galleries#index"
resources :galleries, :only => [:index, :show]
end
# Admin routes
namespace :portfolio, :path => '' do
namespace :admin, :path => Refinery::Core.backend_route do
scope :path => 'portfolio' do
resources :galleries, :except => :show do
get :children, :on => :member
post :update_positions, :on => :collection
resources :items, :except => [:show] do
post :update_positions, :on => :collection
end
end
resources :items do
post :update_positions, :on => :collection
end
end
end
end
end
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3'
end
# Use SCSS for stylesheets
# Use Uglifier as compressor for JavaScript assets
# Use CoffeeScript for .coffee assets and views
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
# Added by Matthew, Thin server
gem 'faye'
gem 'thin'
group :assets do
#gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 4.1.0'
gem 'sass-rails', '~> 5.0'
#gem 'coffee-rails', '~> 3.2.1'
gem 'bootstrap-sass','~> 3.1.1'
gem 'uglifier', '>= 1.3.0'
#gem 'uglifier', '>= 1.0.3'
end
gem 'twitter-bootstrap-rails'
gem 'refinerycms', git: 'https://github.com/refinery/refinerycms', branch: 'master'
#gem 'refinerycms-page-images', '~> 2.0.0'
gem 'quiet_assets', group: :development
#gem 'refinerycms-photo-gallery', '~> 0.1.0'
# Add support for searching inside Refinery's admin interface.
gem 'refinerycms-acts-as-indexed', ['~> 2.0', '>= 2.0.0']
# Add support for Refinery's custom fork of the visual editor WYMeditor.
gem 'refinerycms-wymeditor', ['~> 1.0', '>= 1.0.6']
gem 'refinerycms-portfolio', github: 'refinery/refinerycms-portfolio', branch: 'master'
# The default authentication adapter
gem 'refinerycms-authentication-devise', '~> 1.0'
Looks like it was a bug in the portfolio/images plugin, tried another bundle update and the updated code worked like a charm. <3 RefineryCMS contributors

capybara with rspec visting wrong controller

I am trying to test my controller by filling some values.i have placed my controller spec file under spec/feature. But my visit is not properly working, it is visiting wrong controller.
My controller spec file is
require 'spec_helper'
describe ApplicationsController, :type => :controller do
render_views
#the problem is - we need to test criminal record data block from saferent response
#this guy edwin avila is test input provided by saferent
describe "GET 'new'" , :type => :request do
before do
visit '/TestApplication'
fill_in 'application[applicants_attributes][0][first_name]', :with => 'Rose'
click_link_or_button 'sbmt'
end
it 'has 200 status code if logged in' do
expect(response.status).to eq(200)
end
end
end
My Gem file is
source 'https://rubygems.org'
gem 'rails', '4.0.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 4.0.0'
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'yui-compressor'
end
gem 'jquery-rails'
gem 'git'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
gem 'passenger'
# Deploy with Capistrano
gem 'capistrano'
gem 'rvm-capistrano'
# To use debugger
# gem 'debugger'
gem "xpath", "~> 2.0.0"
gem "formtastic"
gem 'simple_form', :git => 'git://github.com/plataformatec/simple_form.git'
gem "rentjuicer"
gem "capybara", :group => [:development, :test]
#gem "capybara", "~> 2.1.0"
gem "daemons"
gem "mongoid", github: "mongoid/mongoid"
#gem "delayed_job_mongoid" #upto rails 3
gem "bson_ext", '~> 1.5'
gem "whenever", :require => false
gem "bitly", "~> 0.8.0"
gem "mogreet"
gem 'wicked_pdf'
gem 'httparty'
gem 'activemodel'
gem 'actionpack','~> 4.0'
gem "carrierwave-mongoid", "~> 0.6.3"
gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs'
#gem 'client_side_validations'
#gem 'client_side_validations-simple_form'
#gem "client_side_validations-mongoid", "~> 4.1.2"
gem 'twilio-ruby'
gem "rash", "~> 0.4.0"
gem "activeresource", "~> 4.0.0"
gem 'rb-readline', '~> 0.4.2'
gem 'googlecharts'
gem 'htmlentities'
gem 'rspec-rails' , "~> 2.0"
gem 'mongoid-rspec'
gem 'crack'
gem 'simplecov'
#gem 'whoops_rails_logger' upto rails 3
when i try to run
rspec spec/features/applications_controller_spec.rb
i got
Failures:
1) GET 'new' has 200 status code if logged in
Failure/Error: visit '/TestApplication'
NoMethodError:
undefined method `collect' for nil:NilClass
# ./app/controllers/home_controller.rb:8:in `index'
# ./spec/features/applications_controller_spec.rb:8:in `block (2 levels) in <top (required)>'
Finished in 0.14064 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/applications_controller_spec.rb:12 # GET 'new' has 200 status code if logged in
Randomized with seed 32162
my route file
mYAPP::Application.routes.draw do
match 'street/:id' => 'home#street', :as => :street, via: [:get,:post]
match '/pdf' => 'homes#pdf', via: [:get,:post]
match '/login' => 'homes#login', via: [:get,:post]
match '/changing_f_gal' =>'homes#changing_f_gal' , via: [:get,:post]
match '/saferent_test' => 'applications#newnew', via: [:get,:post]
match '/saferent_result' => 'applications#newcreate' , via: [:get,:post]
match '/showall' => 'applications#showall', via: [:get,:post]
match '/visitor/create_visits' => 'visitor#create_visits' , :via => :get
match '/visitor/init_visitor' => 'visitor#init_visitor' , :via => :get
match 'TestApplication' => 'applications#create', :via => :get
root :to => 'home#index'
end
Capybara's visit method won't work for that file path (assuming you're trying to get to the root of your application). Try something like
visit root_path
I'd recommend checking out the documentation at http://jnicklas.github.com/capybara

Heroku throws undefined method `devise_for'

I have an app running local, and it works correctly. I've set up devise on it for OAuth with facebook.
When I push the app to Heroku I get this exception:
/app/app/controllers/users_controller.rb:2:in `<class:SessionsController>':
undefined method `devise_for'
for Users::SessionsController:Class (NoMethodError)
But I don't have this error locally.
These are the steps I took after pushing it to Heroku:
heroku run rake db:migrate
restarted heroku using heroku restart and heroku ps:restart
So the problem isn't that I still have to restart my server.
Here is my gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook'
What could be the issue?
Edit
Here are the first lines of where the error points at:
# app/controllers/users/users_controller
class Users::SessionsController < Devise::SessionsController
devise_for :users, :controllers => { :sessions => "users/sessions" }
end
Did you try running this locally? devise_for should be on your routes, not in the controller see https://github.com/plataformatec/devise to make sure you have your settings correctly. You don't need to override the controller, unless you are doing something special with it. If I where you I'll try to do the least amount of change first, and incrementally change it the way you want.

Factories.rb file is not loading

I'm following ruby on rails tutorials 3.2 by Michael Hartl but when i put gem 'factory_girl_rails', '1.4.0' in my gemfile and run bundle install it shows "bundle complete" as the gem is already loaded in my PC. My problem is it's not generating the factories.rb file in spec folder. What is going wrong?
Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'bootstrap-sass', '2.0.0'
gem 'bcrypt-ruby', '3.0.1'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.9.0'
gem 'annotate', '~> 2.4.1.beta'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.0'
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '1.4.0'
end
group :production do
gem 'pg', '0.12.2'
end
routes.rb:
SAMPLEApp::Application.routes.draw do
resources :users
root to: 'static_pages#home'
match '/signup', to: 'users#new'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
end
Running bundle install won't add any files to your Rails application. It will just download the proper libraries that it needs to use. Sometimes these libraries will come with a rails generator and you would run something like rails generate some_library:install. I don't think that's the case with factory_girl_rails. You probably need to add the file manually.

Resources