Could not find "api_controller.rb" in any of your source paths - ruby-on-rails-5

I am trying to create a Rails 5 api app using http://alessiofanelli.com/blog/building-a-rails-5-and-ember-js-app.
I get the
could not find api_controller.rb
error while executing the scaffold command as below.
$ rails g scaffold team name:string city:string championships:integer
Running via Spring preloader in process 32480 invoke active_record
identical db/migrate/20160204101609_create_teams.rb identical
app/models/team.rb invoke test_unit identical test/models/team_test.rb
identical test/fixtures/teams.yml invoke resource_route route
resources :teams identical app/serializers/team_serializer.rb invoke
scaffold_controller Could not find "api_controller.rb" in any of your
source paths. Your current source paths are:
/home/kpatil/.gem/ruby/gems/active_model_serializers-0.9.4/lib/active_model/serializer/generators/serializer/templates
Which shows below message in terminal
$ rails s
=> Booting Puma
=> Rails 5.0.0.beta2 application starting in development on http://localhost:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
Puma 2.16.0 starting...
Min threads: 0, max threads: 16
Environment: development
Listening on tcp://localhost:3000 Started POST "/teams" for 127.0.0.1 at 2016-02-04 16:25:06 +0530 ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
ActionController::RoutingError (uninitialized constant TeamsController):
activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:259:in const_get' activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:259:inblock in constantize'
activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:257:in each' activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:257:ininject'
activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:257:in constantize' actionpack (5.0.0.beta2) lib/action_dispatch/http/request.rb:93:incontroller_class'
actionpack (5.0.0.beta2) lib/action_dispatch/routing/route_set.rb:44:in controller' actionpack (5.0.0.beta2) lib/action_dispatch/routing

I had the same problem that you. I fixed this issue installing:
gem 'active_model_serializers', '~> 0.10.0.rc1'
Before, I had 0.9.4 version for this gem. Now the scaffold generator works fine.
Regards!

Had the same problem & figured out that this also happens if you have active admin installed.
The solution is then to add in your config/application.rb:
config.app_generators.scaffold_controller = :scaffold_controller

Related

Rails3 MiniMagick load error on choose_processor

A rails 3.2.13 application is running both on localhost and on server (in development mode). In localhost the application loads an image via carrierwave and MiniMagick properly.
On the server, an error is raised
undefined method `size' for nil:NilClass
, with the full stack leading of as such:
mini_magick (3.7.0) lib/mini_magick.rb:24:in `choose_processor'
mini_magick (3.7.0) lib/mini_magick.rb:64:in `mogrify?'
mini_magick (3.7.0) lib/mini_magick/image.rb:360:in `run_command'
mini_magick (3.7.0) lib/mini_magick/image.rb:171:in `valid?'
mini_magick (3.7.0) lib/mini_magick/image.rb:140:in `create'
mini_magick (3.7.0) lib/mini_magick/image.rb:48:in `read'
mini_magick (3.7.0) lib/mini_magick/image.rb:111:in `block in open'
mini_magick (3.7.0) lib/mini_magick/image.rb:110:in `open'
mini_magick (3.7.0) lib/mini_magick/image.rb:110:in `open'
carrierwave (0.9.0) lib/carrierwave/processing/mini_magick.rb:260:in `manipulate!'
Other postings allude to the fact that it may be
a miniMagick version issue. But the localhost version is the same as the server's, as is carrierwave, rails, OSX...
Based on the module documentation, it appears that no processor is being picked up. Thus the installation may have gone awry.
This question is edited as maybe two issues are at hand: different versions of MiniMagick are spawning different behaviours. Both are now separate questions.
Link your identify, convert and other to /usr/local/bin (or /usr/bin) and it will work.
$ which identify
/whatever/identify
$ sudo ln -s /whatever/identify /usr/local/bin
$ which identify
/usr/local/bin/identify
And you need to install:
gem 'mini_magick', '~> 3.5.0'
The problem lies in Passenger v3, and the way it behaves on start-up with Apache. (Passenger 4 apparently does not have the issue)
The solution is the same in any case as per this proposal by editing end of development and/or production environment files with:
ENV['PATH'] = "/usr/local/bin:#{ENV['PATH']}"

Struggling with deploying Rails 3.1 app with Capistrano

We have multiple applications that are currently being deployed using Ruby 1.8.6 with Capistrano. I know, i know, we're working on the upgrade, but these at least deploy just fine.
We have a new application that is running on Ruby 1.8.7, Rails 3.1.11, and we're trying to get deployment going with Bundler and Capistrano. Our applications are in Subversion, and we've always used :deploy_via=>:checkout so that's what i'm trying to use to start.
The behavior i'm seeing is not computing for me, and i've been searching and tweaking for a day or so now:
➜ bundle exec cap deploy
triggering load callbacks
* 2013-11-06 14:13:31 executing `deploy'
* 2013-11-06 14:13:31 executing `deploy:update'
** transaction: start
* 2013-11-06 14:13:31 executing `deploy:update_code'
executing locally: "svn info https://svn-server.com/path/to/branch --username \"myusername\"--password \"mypassword\"--no-auth-cache -rHEAD"
Authentication realm: <https://svn-server.com:443>
Password for 'myusername--password':
*** [deploy:update_code] rolling back
* executing "rm -rf /path/to/deploy/dir/releases/20131106221344; true"
servers: ["myserver.com"]
What seems like the most important line to me:
executing locally: "svn info https://svn-server.com/path/to/branch --username \"myusername\"--password \"mypassword\"--no-auth-cache -rHEAD"
Questions:
Why does 'svn info' even need to be executed locally, when i'm deploying via checkout?
It looks like i'm being prompted for a password because the username/password in the 'svn info' command is being seriously munged??
I'm specifying those credentials in the normal way:
set :scm_username, 'myusername'
set :scm_password, 'mypassword'
Environment info (relevant gems only):
➜ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin12.4.0]
➜ gem -v
1.8.25
➜ gem list --local
*** LOCAL GEMS ***
actionmailer (3.1.12, 3.1.11, 3.0.20)
actionpack (3.1.12, 3.1.11, 3.0.20)
activemodel (3.1.12, 3.1.11, 3.0.20)
activerecord (3.1.12, 3.1.11, 3.0.20)
activeresource (3.1.12, 3.1.11, 3.0.20)
activesupport (3.1.12, 3.1.11, 3.0.20)
bundler (1.3.5, 1.3.1)
capistrano (2.15.5, 2.14.2)
multi_json (1.8.2, 1.8.1, 1.7.9, 1.7.8, 1.7.7)
mysql (2.9.1)
net-scp (1.1.2, 1.1.0)
net-sftp (2.1.2, 2.1.1)
net-ssh (2.7.0, 2.6.8, 2.6.6)
net-ssh-gateway (1.2.0)
rack (1.3.10, 1.2.8)
rack-cache (1.2)
rack-mount (0.8.3, 0.6.14)
rack-ssl (1.3.3)
rack-test (0.6.2, 0.5.7)
rails (3.1.11, 3.0.20)
rails-console-tweaks (1.0.1, 1.0.0)
railties (3.1.12, 3.1.11, 3.0.20)
rake (10.1.0, 10.0.3)
rcov (1.0.0)
rdoc (4.0.1, 3.12.2)
rdoc-data (4.0.1, 3.12)
ruby-debug (0.10.4)
ruby-debug-base (0.10.4)
ruby-debug-ide (0.4.9)
rubygems-bundler (1.1.1)
rvm (1.11.3.6)
rvm-capistrano (1.5.1, 1.4.4, 1.4.1)
sprockets (2.0.4)
tzinfo (0.3.38, 0.3.37)
whenever (0.8.4)
wirb (1.0.2, 1.0.1)
wirble (0.1.3)
If there's more info i can post that would help, please let me know.
Any help or guidance would be much appreciated!
try forcing capistrano version 2.15.4 - I heard there was svn bug in the latest version of the 2 branch

Installing/Running Thin Webserver on Rails 3

Having an issue running the "Thin" web server. It looks like installation was successful but when I run "thin start" It appears as though Thin starts to initialize but then cannot find some resources it needs.
Below, is the audit trail from my terminal session. Can someone offer a hand with this? According to the Thin docs, installation was done correctly. Thanks
Rails 3.2.12
ruby 1.9.3
root#pgateway:/var/www/testapp# gem install thin
Fetching: eventmachine-1.0.0.gem (100%)
Building native extensions. This could take a while...
Fetching: daemons-1.1.9.gem (100%)
Fetching: thin-1.5.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed eventmachine-1.0.0
Successfully installed daemons-1.1.9
Successfully installed thin-1.5.0
3 gems installed
root#pgateway:/var/www/testapp# thin start
>> Using rack adapter
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
/usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/backends /tcp_server.rb:16:in `connect': cannot load such file -- thin/connection (LoadError)
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/backends/base.rb:55:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/backends/base.rb:63:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/server.rb:159:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/controllers/controller.rb:86:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/runner.rb:187:in `run_command'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/runner.rb:152:in `run!'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/bin/thin:6:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/thin:19:in `load'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/thin:19:in `<main>'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `eval'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `<main>'
You seem to install thin separate from rails
Add it to your gemfile and you should be fine
If you want to use a gem, it must be in your Gemfile. You can solve your problem as follows:
Add the following line to your Gemfile: gem 'thin'
Update your current app's environment: bundle install
Then start server
Try to execute the following command:
cd to/your/rails/app
echo 'gem "thin"' >> Gemfile
thin start
this content from https://github.com/macournoyer/thin/issues/115

Spork and Guard EADDRINUSE

I'm building a rails app and using Spork/Guard/Rspec for testing.
I'm on a mac (10.6.8) -- here are the gems I'm using:
gem "rspec-rails", "~> 2.12.1"
gem "guard-rspec", "~> 2.3.3"
gem "guard-spork", "~> 1.4.1"
gem "spork", "~> 0.9.2"
gem 'rb-fsevent', '~> 0.9.1', :require => false
gem "growl", "~> 1.0.3"
gem 'capybara', '1.1.2'
When I edit my routes file it should restart the spork server here's the line in my Guardfile:
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' }, :foreman => true do
watch('config/routes.rb')
end
But recently I just started getting the following error when I add a new route:
Loading Spork.prefork block...
Rack::File headers parameter replaces cache_control after Rack 1.5.
Address already in use - bind(2) (Errno::EADDRINUSE)
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `initialize'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `open'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `open_server'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:759:in `block in open_server'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:757:in `each'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:757:in `open_server'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1342:in `initialize'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1624:in `new'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1624:in `start_service'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125#h/gems/spork-0.9.2/lib/spork/server.rb:29:in `listen'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125#h/gems/spork-0.9.2/lib/spork/server.rb:20:in `run'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125#h/gems/spork-0.9.2/lib/spork/runner.rb:75:in `run'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125#h/gems/spork-0.9.2/lib/spork/runner.rb:10:in `run'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125#h/gems/spork-0.9.2/bin/spork:10:in `<top (required)>'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125#h/bin/spork:23:in `load'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125#h/bin/spork:23:in `<main>'
Usually when spork boots up I get the following:
Loading Spork.prefork block...
Rack::File headers parameter replaces cache_control after Rack 1.5.
Spork is ready and listening on 8989!
How do I avoid this error?
I came here suffering the same problem as the OP.
After going down the rabbit hole of the 'error is a bug' post, and examining the line of code where the failure occurred, I rebooted out of frustration. I realized after doing this that the lock on the port likely came from the fact that I had logged out of the previous desktop session, and that the Spork DRb server hangs RubyMine on closing, so maybe that is what leaves the port open.
Sure enough, I could now start the Spork server.
I add this so other people facing this problem can consider if it matches their situation.
By removing the :foreman => true in the Guardfile I was able to get rid of this problem. Right now I'm not making meaningful use of the values in my .env file in my tests so that should be fine, but I'm submitting an issue on Github.
Looks like this error is a bug: https://github.com/rails/rails/pull/8812

ActiveRecord won't connect to postgresql DB but rake db:migrate works

Just start with rails and Linux a few days a go...
I want to deploy to heroku and one of there best practice is to user postgresql in local environment too anyway... I followed one of there tutorials and created a sample application
the pg gem installed. bundle install works ok. rake db:migrate works and created the table for my application. but... when i try to run my rails page it gives this error:
ActiveRecord::ConnectionNotEstablished
This is the end of the full trace:
> activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `retrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
activerecord (3.2.3) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.3) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__4423031206660944571__call__1711406629982304701__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
i am using pgadmin 3 to see my db. i created a user named schaller which is the same as my user in Ubuntu
my database.yml file:
development:
adapter: postgresql
database: rails
encoding: unicode
username: schaller
password: password123
host: localhost
pool: 5
what else can i check in order for rails to connect to postgres?
edit:
error when starting the rails server in netbeans on webrick
Started GET "/gangs/" for 127.0.0.1 at 2012-09-13 23:12:31 +0300
ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_pool.rb:398:in retrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_specification.rb:168:inretrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_specification.rb:142:in connection'
activerecord (3.2.3) lib/active_record/query_cache.rb:67:inrescue in call'
...
edit the main stuff in my gem file:
gem 'rails', '3.2.3'
gem 'pg'
gem 'thin'
edit:
adding logs for the postgresql connections
[local]
2012-09-15 18:05:35 IDT LOG: connection received: host=127.0.0.1 port=44038
2012-09-15 18:05:35 IDT LOG: connection authorized: user=schaller database=postgres
2012-09-15 18:05:35 IDT LOG: connection received: host=127.0.0.1 port=44039
2012-09-15 18:05:35 IDT LOG: connection authorized: user=schaller database=rails
2012-09-15 18:07:26 IDT LOG: connection received: host=127.0.0.1 port=44048
2012-09-15 18:07:26 IDT LOG: connection authorized: user=schaller database=rails
anyway i see logs being written when i connect with pgadmin 3 and when i run the command, 'rake db:migrate' but not when i run my rails app...
thanks
OK so its been a few days.. i read all answers and comments again because i really needed a solution anyway! the comment left by #Muhammad Sannan did the trick. i am new to rails so i didn't know what an adapter is.. but after a quick google search i ran this command:
gem install activerecord-postgresql-adapter
and that did the trick :)
everything is working now. i just don't understand how db:migrate worked without this adapter..
I think the problem is with your database.yml. You missed production section which is as I think the mode you are using on heroku. Simply add
production:
adapter: postgresql
database: rails
encoding: unicode
username: schaller
password: password123
host: localhost
pool: 5
to your database.yml on heroku
Well, if you can see the db in pgadmin you know the basic connection details are correct. If you've not tinkered in pgadmin, it's unlikely that the port number or other details have changed either.
So - we need to find out what's going on. First step is to turn connection logging on in PostgreSQL and see whether rails is actually connecting. Set log_connections on and restart PG then see what happens. If you don't see anything in the logs, but do from pgadmin then rails isn't seeing the right connection settings.
http://www.postgresql.org/docs/current/static/runtime-config-logging.html#GUC-LOG-CONNECTIONS