Reputation: 768
I upgraded my rails version from 3.2.13 to 4.0.0 and I also upgraded my gems. When I run application from local server, this is the error I am getting:
Started GET "/signup.html" for 127.0.0.1 at 2016-06-24 11:54:37 +0530
ActionController::RoutingError - undefined local variable or method
inherit_resources' for AccountsController:Class: actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:69:in
rescue in controller' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:64:incontroller' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:44:in
call' actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:inblock in call'
call' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:incall' meta_request (0.4.0) lib/meta_request/middlewares/app_request_handler.rb:13:in
call'
meta_request (0.4.0) lib/meta_request/middlewares/meta_request_handler.rb:13:incall'
block in call' warden (1.0.6) lib/warden/manager.rb:34:in
warden (1.0.6) lib/warden/manager.rb:35:incall' client_side_validations (3.0.12) lib/client_side_validations/middleware.rb:17:in
call' rack (1.5.5) lib/rack/etag.rb:23:incall' rack (1.5.5) lib/rack/conditionalget.rb:25:in
call' rack (1.5.5) lib/rack/head.rb:11:incall' remotipart (1.2.1) lib/remotipart/middleware.rb:27:in
call' actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:incall'
call' rack (1.5.5) lib/rack/session/abstract/id.rb:225:in
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:incontext' rack (1.5.5) lib/rack/session/abstract/id.rb:220:in
call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:incall' activerecord (4.0.0) lib/active_record/query_cache.rb:36:in
call' activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:incall' activerecord (4.0.0) lib/active_record/migration.rb:369:in
call' actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:inblock in call'
_run__139117187983862327__call__callbacks' activesupport (4.0.0) lib/active_support/callbacks.rb:80:in
activesupport (4.0.0) lib/active_support/callbacks.rb:373:inrun_callbacks' actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in
call'
rails-dev-tweaks (1.2.0) lib/rails_dev_tweaks/granular_autoload/middleware.rb:36:incall'
call' airbrake (4.3.7) lib/airbrake/rails/middleware.rb:13:in
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:incall' better_errors (2.1.1) lib/better_errors/middleware.rb:84:in
protected_app_call' better_errors (2.1.1) lib/better_errors/middleware.rb:79:inbetter_errors_call'
call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:incall'
call' meta_request (0.4.0) lib/meta_request/middlewares/headers.rb:16:in
rack-contrib (1.4.0) lib/rack/contrib/response_headers.rb:17:incall' actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in
call'
railties (4.0.0) lib/rails/rack/logger.rb:38:incall_app' railties (4.0.0) lib/rails/rack/logger.rb:21:in
block in call' activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:inblock in tagged'
tagged' activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:intagged' railties (4.0.0) lib/rails/rack/logger.rb:21:in
call' actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:incall' rack (1.5.5) lib/rack/methodoverride.rb:21:in
call' rack (1.5.5) lib/rack/runtime.rb:17:incall' activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in
call' rack (1.5.5) lib/rack/lock.rb:17:incall' actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in
call' airbrake (4.3.7) lib/airbrake/user_informer.rb:16:in_call' airbrake (4.3.7) lib/airbrake/user_informer.rb:12:in
call' railties (4.0.0) lib/rails/engine.rb:511:incall' railties (4.0.0) lib/rails/application.rb:97:in
call' rack (1.5.5) lib/rack/content_length.rb:14:incall' thin (1.5.1) lib/thin/connection.rb:81:in
block in pre_process' thin (1.5.1) lib/thin/connection.rb:79:inpre_process' thin (1.5.1) lib/thin/connection.rb:54:in
process' thin (1.5.1) lib/thin/connection.rb:39:inreceive_data' eventmachine (1.0.9) lib/eventmachine.rb:193:in
run' thin (1.5.1) lib/thin/backends/base.rb:63:instart' thin (1.5.1) lib/thin/server.rb:159:in
start' rack (1.5.5) lib/rack/handler/thin.rb:16:inrun' rack (1.5.5) lib/rack/server.rb:264:in
start' railties (4.0.0) lib/rails/commands/server.rb:84:instart' railties (4.0.0) lib/rails/commands.rb:78:in
block in ' railties (4.0.0) lib/rails/commands.rb:73:in<top (required)>' railties (4.0.0) lib/rails/app_rails_loader.rb:43:in
block in exec_app_rails' railties (4.0.0) lib/rails/app_rails_loader.rb:32:inexec_app_rails' railties (4.0.0) lib/rails/cli.rb:6:in
' railties (4.0.0) bin/rails:9:in<top (required)>' () home/user/.rvm/gems/ruby-2.3.0@project/bin/rails:23:in
' () home/user/.rvm/gems/ruby-2.3.0@project/bin/ruby_executable_hooks:15:in `'
In my previous version, the routes file is like this:
match '/signup' => 'accounts#new', :plan => 'year'
After upgrading, I changed it as:
get '/signup' => 'accounts#new', :plan => 'year'
"match"is replaced by "get" for all the routes.
This is the accounts_controller where we used inherited_resources.
class AccountsController < ApplicationController
inherit_resources
ssl_required :new, :create
before_filter :authenticate_user!, :except => [:new, :create]
...................
end
I couldn't trace why they are used and couldn't find this in Gemfile. Please help me to fix this error.
Upvotes: 1
Views: 686
Reputation: 406
inherit_resources was intended to dry up the controller that uses REST conventions. It is a deprecated gem and it no longer maintained in Rails 4. inherit_resources will essentially inherit from InheritedResources::Base which has the REST methods pre-defined.
Instead you can just remove it and define your routes within your controller like you normally would:
class AccountsController < ApplicationController
ssl_required :new, :create
before_filter :authenticate_user!, :except => [:new, :create]
def index
@accounts = Accounts.all
end
def show
@account = Account.find(params[:id])
end
def new
@account = Account.new
end
def create
@account = Account.new(account_params)
if @account.save
redirect_to @account
else
render 'new'
end
end
def edit
@account = Account.find(params[:id])
end
def update
@account = Account.find(params[:id])
if @account.update_attributes(account_params)
flash[:notice] = "Successfully updated account!"
redirect_to @account
else
render 'edit'
end
end
def destroy
@account = Account.find(params[:id])
@account.destroy
redirect_to accounts_path
end
private
def account_params
params.require(:account).permit(:name, :email, etc) # Look up strong params if you are unfamiliar. The name, email, etc. are going to be the only permitted params passed in the methods above as a safety feature so you have to permit the fields being created here.
end
That is an outline of what inherited resources was adding into the controller with the intent of having "Fat models and skinny controllers". You can find other gems that do similar things, but in my opinion I rather just add the methods myself for readability.
EDIT: It was adding these method definitions, but depending on your app will define what is inside these methods. This would be my best rough guess. Something new in Rails 4 too is the addition of strong params. In the create and update actions you see account_params being called from a private method instead of updating with the raw params inside the methods.
Upvotes: 1