Adding a column to model results in RangeError [Refactoring] - ruby-on-rails

I'm currently working on a assignment for ruby on rails course I'm doing. I have to refactor a blog app written in Rails and add the functionality to merge articles.
What I did was to add a new text field in the form that is displayed when you edit the article
<%= text_field 'article', 'merge' %>
After I do that, it complains that there is no merge method in article model so I went ahead and implemented that.
I run the following migration:
class AddMergeWithToContents < ActiveRecord::Migration
def self.up
add_column :contents, :merge_with, :integer
end
def self.down
remove_column :contents, :merge_with
end
end
Then, when when accessing again the app it gives me the following error:
RangeError in Admin::SettingsController#update_database
bignum too big to convert into `long'
Rails.root: /home/saasbook/typo
Application Trace | Framework Trace | Full Trace
app/controllers/admin/settings_controller.rb:38:in `[]'
app/controllers/admin/settings_controller.rb:38:in `update_database'
Full Trace
app/controllers/admin/settings_controller.rb:38:in `[]'
app/controllers/admin/settings_controller.rb:38:in `update_database'
actionpack (3.0.17) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.17) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.17) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.17) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.17) lib/active_support/callbacks.rb:457:in `block in _run__331447277__process_action__533401003__callbacks'
activesupport (3.0.17) lib/active_support/callbacks.rb:221:in `block in _conditional_callback_around_20300'
activesupport (3.0.17) lib/active_support/callbacks.rb:331:in `around'
activesupport (3.0.17) lib/active_support/callbacks.rb:315:in `_callback_around_20297'
activesupport (3.0.17) lib/active_support/callbacks.rb:220:in `_conditional_callback_around_20300'
activesupport (3.0.17) lib/active_support/callbacks.rb:456:in `_run__331447277__process_action__533401003__callbacks'
activesupport (3.0.17) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.17) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.17) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.17) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.17) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.17) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.17) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.17) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.17) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.17) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.17) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.17) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.17) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.17) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.17) lib/action_dispatch/routing/route_set.rb:68:in `call'
actionpack (3.0.17) lib/action_dispatch/routing/route_set.rb:68:in `dispatch'
actionpack (3.0.17) lib/action_dispatch/routing/route_set.rb:33:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:75:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.17) lib/action_dispatch/routing/route_set.rb:499:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.5) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.17) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.17) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.17) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.17) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.17) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.17) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.17) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.5) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.17) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.17) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.5) lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.5) lib/rack/lock.rb:13:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.17) lib/rails/application.rb:168:in `call'
railties (3.0.17) lib/rails/application.rb:77:in `method_missing'
railties (3.0.17) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.5) lib/rack/content_length.rb:13:in `call'
rack (1.2.5) lib/rack/handler/webrick.rb:52:in `service'
/home/saasbook/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/saasbook/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/saasbook/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
This is the settings controller
class Admin::SettingsController < Admin::BaseController
cache_sweeper :blog_sweeper
def index
if this_blog.base_url.blank?
this_blog.base_url = blog_base_url
end
load_settings
end
def write; load_settings end
def feedback; load_settings end
def errors; load_settings; end
def redirect
flash[:notice] = _("Please review and save the settings before continuing")
redirect_to :action => "index"
end
def update
if request.post?
Blog.transaction do
params[:setting].each { |k,v| this_blog.send("#{k.to_s}=", v) }
this_blog.save
flash[:notice] = _('config updated.')
end
redirect_to :action => params[:from]
end
rescue ActiveRecord::RecordInvalid
render params[:from]
end
def update_database
#current_version = Migrator.current_schema_version
#needed_version = Migrator.max_schema_version
#support = Migrator.db_supports_migrations?
#needed_migrations = Migrator.available_migrations[#current_version..#needed_version].collect do |mig|
mig.scan(/\d+\_([\w_]+)\.rb$/).flatten.first.humanize
end
end
def migrate
if request.post?
Migrator.migrate
redirect_to :action => 'update_database'
end
end
private
def load_settings
#setting = this_blog
end
end
Any help would be really appreciated. Thanks.

So to just answer the question, you can change the text_field to text_field_tag and remove the first argument. Or you can add a "setter" method to your article model named merge=(val) in which you can code whatever you need to. Hope this helps!

Related

rails 6: no implicit conversion of String into Integer

I've been trying to learn ruby(2.6.3) on rails(6.0.1) by following a project to make an Instagram clone.
When I try to create a new post I get "no implicit conversion of String into Integer app/controllers/posts_controller.rb:8:in `create' ". I'm confused because I do not see a string to int so i'm wondering if it is something i'm missing with ruby. I've tried updating my gem versions and also tried adding the "strong_parameters" gem but that did not seem to fix my problem. Thank you for any insight as to what i'm doing wrong
Post_controller.rb
class PostsController < ApplicationController
def new
#post = Post.new
end
def create
#post = Post.new(post_params)
if #post.save
redirect_to dashboard_path, flash: {success: "Post was created successfully!"}
else
redirect_to new_post_path, flash: {danger: "Post failed to save!"}
end
end
def show
end
private
def post_params
params.require(:post).permit(:image, :image_cache)
end
end
Posts table migrate
class CreatePosts < ActiveRecord::Migration[6.0]
def change
create_table :posts do |t|
t.string :image
t.boolean :active
t.references :account
t.timestamps
end
end
end
Post Model
class Post < ApplicationRecord
mount_uploader :image, ImageUploader
end
Post table schema
create_table "posts", force: :cascade do |t|
t.string "image"
t.boolean "active"
t.bigint "account_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["account_id"], name: "index_posts_on_account_id"
end
Full stack trace
carrierwave (2.0.2) lib/carrierwave/sanitized_file.rb:312:in `chmod'
carrierwave (2.0.2) lib/carrierwave/sanitized_file.rb:312:in `chmod!'
carrierwave (2.0.2) lib/carrierwave/sanitized_file.rb:220:in `copy_to'
carrierwave (2.0.2) lib/carrierwave/uploader/cache.rb:141:in `cache!'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:63:in `block (2 levels) in cache'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:176:in `handle_error'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:47:in `block in cache'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:46:in `map'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:46:in `cache'
carrierwave (2.0.2) lib/carrierwave/mount.rb:146:in `image='
carrierwave (2.0.2) lib/carrierwave/mount.rb:373:in `image='
carrierwave (2.0.2) lib/carrierwave/orm/activerecord.rb:75:in `image='
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:51:in `public_send'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:51:in `_assign_attribute'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:44:in `block in _assign_attributes'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:43:in `each'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:43:in `_assign_attributes'
activerecord (6.0.1) lib/active_record/attribute_assignment.rb:22:in `_assign_attributes'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:35:in `assign_attributes'
activerecord (6.0.1) lib/active_record/core.rb:326:in `initialize'
activerecord (6.0.1) lib/active_record/inheritance.rb:70:in `new'
activerecord (6.0.1) lib/active_record/inheritance.rb:70:in `new'
app/controllers/posts_controller.rb:8:in `create'
actionpack (6.0.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.1) lib/abstract_controller/base.rb:196:in `process_action'
actionpack (6.0.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.1) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (6.0.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (6.0.1) lib/action_dispatch/routing/route_set.rb:51:in `dispatch'
actionpack (6.0.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.1) lib/action_dispatch/routing/route_set.rb:837:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.0.7) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.7) lib/rack/etag.rb:25:in `call'
rack (2.0.7) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.7) lib/rack/head.rb:12:in `call'
actionpack (6.0.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.7) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.7) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.1) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web-console (4.0.1) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/method_override.rb:22:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
webpacker (4.2.0) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.1) lib/rails/engine.rb:526:in `call'
puma (4.3.1) lib/puma/configuration.rb:228:in `call'
puma (4.3.1) lib/puma/server.rb:681:in `handle_request'
puma (4.3.1) lib/puma/server.rb:472:in `process_client'
puma (4.3.1) lib/puma/server.rb:328:in `block in run'
puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
Carrierwave config
CarrierWave.configure do |config| config.fog_credentials = { provider: 'AWS', aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], } config.storage = :fog config.permissions = "0666" config.cache_dir = "#{Rails.root}/tmp/" config.fog_directory = ENV['FOG_DIRECTORY'] config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" }end
almost always when I see this, it is passing a string into the index of an array. Sorry to be vague, but I don't see where that would happen in your code.

Ruby on Rails NoMethodError: undefined method `[]' for nil:NilClass

I'm new to ruby on rails and currently working on a web application which uses the 'rspotify' gem to interact with the Spotify API.
I have a controller called 'genre' which I use to direct my search results from the index page. However, it won't let me initialize any variables inside the index function.
This is what my controller looks like
# genre_controller.rb
def index
if params[:search]
#genres = RSpotify::Recommendations.generate(limit: 20, seed_genres: ['country'])
# render :json => #songs
else
redirect_to root_path
end
end
This is what my my index page looks like
<h1>Genre#index</h1>
<p>Find me in app/views/genre/index.html.erb</p>
<h1 class="page-header">Music Matching <%= params[:search] %></h1>
<ul>
<% #music.each do |music| %>
<li><%= music.name %> | <%= link_to "Show", genre_path(music.id) %></li>
<% end %>
</ul>
This is what my routes look like
get 'genre/index'
get 'genre/show', to:'genre#show', as: 'genre'
get 'site/index'
root 'site#index'
I get an error on line 4 of my genre controller, where I call the RSpotify method. Any variable I try to instantiate there returns a NoErrorMethod.
Any help is appreciated, thanks!
Edit:
Here's the exception I get from the console
NoMethodError (undefined method `[]' for nil:NilClass):
app/controllers/genre_controller.rb:4:in `index'
Started GET "/genre/index?utf8=%E2%9C%93&search=hello" for 127.0.0.1 at 2018-02-19 16:14:59 -0800
Processing by GenreController#index as HTML
Parameters: {"utf8"=>"✓", "search"=>"hello"}
Completed 500 Internal Server Error in 295ms
Here's the full tracestack from the exception
rspotify (1.27.0) lib/rspotify/recommendations.rb:101:in `initialize'
rspotify (1.27.0) lib/rspotify/recommendations.rb:97:in `new'
rspotify (1.27.0) lib/rspotify/recommendations.rb:97:in `generate'
app/controllers/genre_controller.rb:4:in `index'
actionpack (5.1.4) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.1.4) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.4) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.1.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.1.4) lib/active_support/callbacks.rb:131:in `run_callbacks'
actionpack (5.1.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.4) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.4) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.1.4) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.4) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.4) lib/active_support/notifications.rb:166:in `instrument'
actionpack (5.1.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.4) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
activerecord (5.1.4) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
actionpack (5.1.4) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.4) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.4) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.4) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:834:in `call'
rack (2.0.4) lib/rack/etag.rb:25:in `call'
rack (2.0.4) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.4) lib/rack/head.rb:12:in `call'
rack (2.0.4) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.4) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.4) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.4) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.4) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.4) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.4) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.4) lib/rack/method_override.rb:22:in `call'
rack (2.0.4) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
railties (5.1.4) lib/rails/engine.rb:522:in `call'
puma (3.11.2) lib/puma/configuration.rb:225:in `call'
puma (3.11.2) lib/puma/server.rb:624:in `handle_request'
puma (3.11.2) lib/puma/server.rb:438:in `process_client'
puma (3.11.2) lib/puma/server.rb:302:in `block in run'
puma (3.11.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
I got a similar error as above when I tried to connect to the Spotify API. The documentation on rspotify missed out the fact that you need to run the authenticate method before you do anything with the API.
i.e.
RSpotify.authenticate("<your_client_id>", "<your_client_secret>")

Uploading multiple images with paperclip?

I've looked at all the other questions on SO that look similar but I can't find an answer that will help me.
I'm working on upgrading an app that was written a while ago and am struggling to get the image upload section of it working. The relevant bits of code are as follows:
photos_controller.rb:
def create
images = params[:an_image]
if !images.nil?
photos = []
images.each do |image|
photo = #trip.photos.build(:user => current_user, :trip => #trip, :image => image)
if photo.save
p 'saving ok'
photos << photo
else
p 'ERROR saving'
end
end
add_news('created_multiple', photos.first, {:photo_ids => photos.collect(&:id)})
flash[:notice] = "Your photos were updated successfully!"
redirect_to #trip
else
#photo.user = current_user
#photo.trip = #trip
if #photo.update_attributes(params[:photo]) || params[:photo][:an_image]
add_news('created', #photo)
redirect_to trip_photos_url(#photo.trip)
else
render :edit
end
end
end
photo.rb:
def an_image=(file)
self.trip.photos.create(:image => file)
end
attr_accessor :an_image
# Photo image
if Rails.env.test?
has_attached_file :image, :path => "/tmp/:attachment-:id-:style.:extension"
else
has_attached_file :image,
# 200 x 160 for news
:styles => {
:list => "270x200>",
:feed_item => "75x60>",
:map => "30x30#",
:homepage => "160x110#",
:normal => "300x500",
:tiny => "20x20#"
},
:processors => [:auto_orient, :thumbnail],
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => "saild-production",
:convert_options => {:map => '-bordercolor white -compose over -border 2'}
end
and photos/new.html.erb:
<div id="content-four">
<h1>Upload photos to <%= #trip.name %></h1>
<%= form_tag trip_photos_path(#trip), :multipart => true %>
<form id="post-photo" action="#">
<fieldset class="multiple-uploads">
Add more files<br>
<%= file_field_tag :an_image, :class => 'file-upload' %>
<script type="text/javascript">
$('.duplicate').click(function() {
$('.file-upload:first').clone().appendTo($('.multiple-uploads'))
})
</script>
</fieldset>
<fieldset>
<input type="submit" class="submit button" value="Publish"/>
</fieldset>
</form>
</div>
But when I try to upload a file I keep getting this error:
NoMethodError (undefined method `each' for #<ActionDispatch::Http::UploadedFile:0x007f971263b860>):
app/controllers/photos_controller.rb:33:in `create'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.7) lib/active_support/callbacks.rb:461:in `_run__1507672816926971504__process_action__674209566928286804__callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.7) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.7) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:75:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:493:in `call'
hoptoad_notifier (2.4.11) lib/hoptoad_notifier/rack.rb:27:in `call'
sass (3.4.12) lib/sass/plugin/rack.rb:54:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.8) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.7) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.7) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.8) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
airbrake (4.1.0) lib/airbrake/rails/middleware.rb:13:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.7) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.8) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.7) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.8) lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.8) lib/rack/lock.rb:13:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/static.rb:30:in `call'
airbrake (4.1.0) lib/airbrake/user_informer.rb:16:in `_call'
airbrake (4.1.0) lib/airbrake/user_informer.rb:12:in `call'
hoptoad_notifier (2.4.11) lib/hoptoad_notifier/user_informer.rb:12:in `call'
railties (3.0.7) lib/rails/application.rb:168:in `call'
railties (3.0.7) lib/rails/application.rb:77:in `method_missing'
railties (3.0.7) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.8) lib/rack/content_length.rb:13:in `call'
rack (1.2.8) lib/rack/handler/webrick.rb:52:in `service'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
What I think the code is trying to do is create an array of the images that are uploaded and then .build(which I've never come across -> I assume it is like .create?) with them individually, but it doesn't seem to want to put the uploaded files into an array...
Does anyone know how I can fix this?
(I'm running Rails 3.0.7 and Ruby 1.9.3)
Your problem is that params[:an_image] is a single object, and you call .each on it as if it was an array.
I've not tried this with file data before, but try changing the name attribute of the file_field_tag to have square brackets at the end, like
file_field_tag "an_image[]"
When you have [] at the end of the name attribute, then the values from all inputs with the same name attribute will be collected together into an array. Might be as simple as that...on the other hand, there might be something about how the multipart data is structured which prevents this.
Another tip, if you have to deal with a variable that might be an array or a single object, is to wrap it in an array, and then call flatten on it. eg
#turns foos into an array, whether it is a single object or an array already
foos = [foos].flatten
Now you can do foos.each, safe in the knowledge that it will always be an array.
Also - tail your development.log file when your form submits and you can see what's in params, and compare it to what your code is expecting.

AMQP/RabbitMQ-Server/EventMachine with PhusionPassenger/Rails Crashes

I'm using AMQP / RabbitMQ for my Ruby on Rails app.
I put the following amqp.rb file under config/initializers:
(Copied and changed from a Recipe: http://www.hiringthing.com/2011/11/04/eventmachine-with-rails.html#sthash.iqCWUtOn.dpbs)
require 'amqp'
# References:
# 1. Getting Started with AMQP and Ruby
# http://rubyamqp.info/articles/getting_started/
# 2. EventMachine and Rails
# http://www.hiringthing.com/2011/11/04/eventmachine-with-rails.html#sthash.iqCWUtOn.dpbs
# 3. Connecting to the broker, integrating with Ruby on Rails, Merb and Sinatra
# http://rubyamqp.info/articles/connecting_to_broker/
module AppEventMachine
def self.start
if defined?(PhusionPassenger)
Rails.logger.info "###############################################################################"
Rails.logger.info "Running EventMachine/Rails with PhusionPassenger ......"
Rails.logger.info "###############################################################################"
PhusionPassenger.on_event(:starting_worker_process) do |forked|
# => for passenger, we need to avoid orphaned threads
if forked && EventMachine.reactor_running?
EventMachine.stop
end
spawn_eventmachine_thread
die_gracefully_on_signal
end
else
Rails.logger.info "###############################################################################"
Rails.logger.info "PhusionPassenger is not running. Probably you are running Rails locally ......"
Rails.logger.info "###############################################################################"
# faciliates debugging
Thread.abort_on_exception = true
# just spawn a thread and start it up
spawn_eventmachine_thread unless defined?(Thin)
# Thin is built on EventMachine, doesn't need this thread
end
end
def self.spawn_eventmachine_thread
Thread.new {
Rails.logger.error "**************************Begin"
EventMachine.run do
Rails.logger.error "**************************1"
AMQP.channel ||= AMQP::Channel.new(AMQP.connect(:host => '127.0.0.1')) # Q_SERVER, :user=> Q_USER, :pass => Q_PASS, :vhost => Q_VHOST ))
Rails.logger.error "**************************2"
AMQP.channel.on_error(&method(:handle_channel_exception))
Rails.logger.error "**************************3"
AMQP.channel.queue(MixpanelJob::QUEUE_NAME, :exclusive => true)
.subscribe { |metadata, payload| MixpanelJob::handle_sending(metadata, payload) }
Rails.logger.error "**************************4"
end
Rails.logger.error "***************************End"
}
end
def self.handle_channel_exception(channel, channel_close)
Rails.logger.error "###############################################################################"
Rails.logger.error "Oops... a channel-level exception: code = #{channel_close.reply_code}, message = #{channel_close.reply_text}"
Rails.logger.error "###############################################################################"
end
def self.die_gracefully_on_signal
Signal.trap("INT") {
Rails.logger.error "###############################################################################"
Rails.logger.error "Stopping the EventMachine ......"
EventMachine.stop
Rails.logger.error "###############################################################################"
}
Signal.trap("TERM") {
Rails.logger.error "###############################################################################"
Rails.logger.error "Stopping the EventMachine ......"
EventMachine.stop
Rails.logger.error "###############################################################################"
}
end
end
AppEventMachine.start
But when I start the server and try to browser to its root, I got:
###############################################################################
Running EventMachine/Rails with PhusionPassenger ......
###############################################################################
**************************Begin
Started GET "/" for 10.130.40.254 at 2013-07-29 18:54:07 -0400
**************************1
**************************2
**************************3
**************************4
Processing by UsersController#my_app as HTML
Completed 500 Internal Server Error in 1ms
TypeError ([9] is not a symbol):
activesupport (3.2.3) lib/active_support/inflector/methods.rb:229:in `const_defined?'
activesupport (3.2.3) lib/active_support/inflector/methods.rb:229:in `block in constantize'
activesupport (3.2.3) lib/active_support/inflector/methods.rb:228:in `each'
activesupport (3.2.3) lib/active_support/inflector/methods.rb:228:in `constantize'
devise (2.1.2) lib/devise/rails/warden_compat.rb:27:in `deserialize'
warden (1.2.1) lib/warden/session_serializer.rb:35:in `fetch'
warden (1.2.1) lib/warden/proxy.rb:212:in `user'
warden (1.2.1) lib/warden/proxy.rb:318:in `_perform_authentication'
warden (1.2.1) lib/warden/proxy.rb:127:in `authenticate!'
devise (2.1.2) lib/devise/controllers/helpers.rb:48:in `authenticate_user!'
activesupport (3.2.3) lib/active_support/callbacks.rb:429:in `_run__125924433__process_action__89218244__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_process_action_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.3) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.3) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.4) lib/rack/etag.rb:23:in `call'
rack (1.4.4) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.4) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.4) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.3) lib/active_record/query_cache.rb:64: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__178400477__call__834586844__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/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'
railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.4) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.4) lib/rack/lock.rb:15:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.3) lib/rails/engine.rb:479:in `call'
railties (3.2.3) lib/rails/application.rb:220:in `call'
railties (3.2.3) lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/utils.rb:470:in `safe_fork'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server.rb:180:in `start'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
<internal:prelude>:10:in `synchronize'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.19/helper-scripts/passenger-spawn-server:99:in `<main>'
Thanks to Joshua's comment. It turns out that it had nothing to do with PhusionPassenger or AMQP or RabbitMQ-Server. It's because of my Chrome cookies cache.
I cleared my cache, and now everything just works like charm.
Since my Rails throw an error, however, I think there is a bug in Ruby on Rails dealing with devise (or other gems) cookies.

ArgumentError, wrong number of arguments (2 for 0) in create action, works on Heroku but not on local server

I recently had a RoR application developed for me by a third party and now I'm on my own to add future features that I want. It works on Heroku, but when I try to run it on localhost:3000, I get an ArgumentError. I have not changed any of the code, I just pulled it from github and tried to run it on a local development server to implement new changes. I've asked them about this problem, but they are not sure of the cause, so here goes...
We're running ruby 1.9.2, rails 3.0.7
Whenever I try to save a project on my site, or whenever .save is called on an object, I get an ArgumentError, wrong number of arguments (2 for 0).
Application Trace
app/controllers/users/projects_controller.rb:24:in `create'
Full Trace
activesupport (3.0.7) lib/active_support/ordered_hash.rb:16:in `block in to_yaml'
/home/squizzleflip/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/deprecated.rb:19:in `call'
/home/squizzleflip/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/deprecated.rb:19:in `block in quick_emit'
/home/squizzleflip/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:296:in `dump_coder'
/home/squizzleflip/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:61:in `accept'
/home/squizzleflip/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:36:in `<<'
/home/squizzleflip/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:165:in `dump'
activerecord (3.0.7) lib/active_record/base.rb:1720:in `block in arel_attributes_values'
activerecord (3.0.7) lib/active_record/base.rb:1713:in `each'
activerecord (3.0.7) lib/active_record/base.rb:1713:in `arel_attributes_values'
activerecord (3.0.7) lib/active_record/persistence.rb:265:in `create'
activerecord (3.0.7) lib/active_record/timestamp.rb:47:in `create'
activerecord (3.0.7) lib/active_record/callbacks.rb:277:in `block in create'
activesupport (3.0.7) lib/active_support/callbacks.rb:414:in `_run_create_callbacks'
activerecord (3.0.7) lib/active_record/callbacks.rb:277:in `create'
activerecord (3.0.7) lib/active_record/persistence.rb:246:in `create_or_update'
activerecord (3.0.7) lib/active_record/callbacks.rb:273:in `block in create_or_update'
activesupport (3.0.7) lib/active_support/callbacks.rb:424:in `_run_save_callbacks'
activerecord (3.0.7) lib/active_record/callbacks.rb:273:in `create_or_update'
activerecord (3.0.7) lib/active_record/persistence.rb:39:in `save'
activerecord (3.0.7) lib/active_record/validations.rb:43:in `save'
activerecord (3.0.7) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (3.0.7) lib/active_record/transactions.rb:240:in `block (2 levels) in save'
activerecord (3.0.7) lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
activerecord (3.0.7) lib/active_record/transactions.rb:207:in `transaction'
activerecord (3.0.7) lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
activerecord (3.0.7) lib/active_record/transactions.rb:240:in `block in save'
activerecord (3.0.7) lib/active_record/transactions.rb:251:in `rollback_active_record_state!'
activerecord (3.0.7) lib/active_record/transactions.rb:239:in `save'
app/controllers/users/projects_controller.rb:24:in `create'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.7) lib/active_support/callbacks.rb:448:in `_run__334044120__process_action__677517956__callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.7) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.7) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:493:in `call'
warden (1.0.6) lib/warden/manager.rb:35:in `block in call'
warden (1.0.6) lib/warden/manager.rb:34:in `catch'
warden (1.0.6) lib/warden/manager.rb:34:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.4) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.7) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.7) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.4) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.7) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.7) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.4) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.4) lib/rack/lock.rb:11:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.7) lib/rails/application.rb:168:in `call'
railties (3.0.7) lib/rails/application.rb:77:in `method_missing'
railties (3.0.7) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.4) lib/rack/content_length.rb:13:in `call'
rack (1.2.4) lib/rack/handler/webrick.rb:52:in `service'
/home/squizzleflip/.rvm/rubies/ruby-1.9.2- p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/squizzleflip/.rvm/rubies/ruby-1.9.2- p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/squizzleflip/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
the code from projects_controller, line 24 is the if statement
def create
#project = Project.new(params[:project])
#project.memberships.build(:user_id => current_profile.id, :pending => false)
if #project.save
redirect_to destination, :notice => 'Project was successfully created.'
else
build_project_associations_for_nested_forms
render :action => 'new'
end
end
I'm a bit new at this, so I'm not quite sure what else is needed to determine the problem.
Have you tried running something other than WEBrick (assuming you're using that)? Try installing Thin (gem install thin) and see if the problem persists.
Make sure that you have got all the required gem, run bundle install:
bundle install
Restart the app, hopefully that helps.

Resources