Rails 3.2.17 NoMethodError in VideosController#create - ruby-on-rails-3

I'm new to Ruby on Rails and trying to create a relatively simple web application by following this guide: http://www.sitepoint.com/youtube-rails/. I've come to a point where all the code is in place but still getting the NoMethodError in VideosController#create:
undefined method `uid=' for #<Video:0x007fb066c41d28>
app/controllers/videos_controller.rb
class VideosController < ApplicationController
def index
#videos = Video.order('created_at DESC')
end
def new
#video = Video.new
end
def create
#video = Video.new(params[:video])
if #video.save
flash[:success] = 'Video added!'
redirect_to root_url
else
render 'new'
end
end
end
app/models/video.rb
class Video < ActiveRecord::Base
attr_accessible :link
YT_LINK_FORMAT = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/i
validates :link, presence: true, format: YT_LINK_FORMAT
before_create -> do
uid = link.match(YT_LINK_FORMAT)
self.uid = uid[2] if uid && uid[2]
if self.uid.to_s.length != 11
self.errors.add(:link, 'is invalid.')
false
elsif Video.where(uid: self.uid).any?
self.errors.add(:link, 'is not unique.')
false
else
get_additional_info
end
end
private
def get_additional_info
begin
client = YouTubeIt::OAuth2Client.new(dev_key: '<my_dev_key>')
video = client.video_by(uid)
self.title = video.title
self.duration = parse_duration(video.duration)
self.author = video.author.name
self.likes = video.rating.likes
self.dislikes = video.rating.dislikes
rescue
self.title = '' ; self.duration = '00.00.00' ; self.author = '' ; self.likes = 0 ; self.dislikes = 0
end
end
def parse_duration(d)
hr = (d / 3600).floor
min = ((d - (hr * 3600)) / 60).floor
sec = (d - (hr * 3600) - (min * 60)).floor
hr = '0' + hr.to_s if hr.to_i < 10
min = '0' + min.to_s if min.to_i < 10
sec = '0' + sec.to_s if sec.to_i < 10
hr.to_s + ':' + min.to_s + ':' + sec.to_s
end
end
Full Trace
activemodel (3.2.17) lib/active_model/attribute_methods.rb:407:in `method_missing'
activerecord (3.2.17) lib/active_record/attribute_methods.rb:149:in `method_missing'
app/models/video.rb:10:in `block in <class:Video>'
activesupport (3.2.17) lib/active_support/callbacks.rb:407:in `_run__3695319422649908747__create__1619689881822406221__callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.17) lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:81:in `run_callbacks'
activerecord (3.2.17) lib/active_record/callbacks.rb:268:in `create'
activerecord (3.2.17) lib/active_record/persistence.rb:348:in `create_or_update'
activerecord (3.2.17) lib/active_record/callbacks.rb:264:in `block in create_or_update'
activesupport (3.2.17) lib/active_support/callbacks.rb:403:in `_run__3695319422649908747__save__1619689881822406221__callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.17) lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:81:in `run_callbacks'
activerecord (3.2.17) lib/active_record/callbacks.rb:264:in `create_or_update'
activerecord (3.2.17) lib/active_record/persistence.rb:84:in `save'
activerecord (3.2.17) lib/active_record/validations.rb:50:in `save'
activerecord (3.2.17) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (3.2.17) lib/active_record/transactions.rb:259:in `block (2 levels) in save'
activerecord (3.2.17) lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
activerecord (3.2.17) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.2.17) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.2.17) lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
activerecord (3.2.17) lib/active_record/transactions.rb:259:in `block in save'
activerecord (3.2.17) lib/active_record/transactions.rb:270:in `rollback_active_record_state!'
activerecord (3.2.17) lib/active_record/transactions.rb:258:in `save'
app/controllers/videos_controller.rb:12:in `create'
actionpack (3.2.17) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.17) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.17) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.17) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.17) lib/active_support/callbacks.rb:414:in `_run__333554687839828986__process_action__1999722818964258122__callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.17) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.17) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.17) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.17) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.17) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.17) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.17) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.17) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.17) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.17) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.17) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.17) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.17) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.17) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.17) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.17) 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.17) lib/action_dispatch/routing/route_set.rb:608:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.17) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.17) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `_run__469011070482330715__call__1619689881822406221__callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.17) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.17) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.17) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.17) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.17) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.17) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.17) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/static.rb:63:in `call'
railties (3.2.17) lib/rails/engine.rb:484:in `call'
railties (3.2.17) lib/rails/application.rb:231:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.17) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/Users/<User_Name>/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/Kappe/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/Kappe/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
I hope I've given enough information. I think something is going on in video.rb where uid and self.uid are set but I don't have enough knowledge to solve this problem. Can you help me with this? Thanks in advance!

undefined method `uid=' for #
The error is because there is no uid attribute in videos table.
You should add that attribute through migration
AddUidToVideo uid:string
this will create a migration file for adding a uid column to that table then
do rake db:migrate

Related

Undefined method `map' for 1:Fixnum

I want to email users every time a new treatment that is under the category they are interested in is added.
I have a join table interests_users which is holds a user_id and a interest_id. Treatments has a variable called category which is used to compare against interests.
This is what the create block in my treatments controller looks like.
def create
#treatment = Treatment.new(treatment_params)
respond_to do |format|
if #treatment.save
interest = Interest.find_by(name: #treatment.category)
if interest
User.find_by_sql("SELECT * FROM users
INNER JOIN interests_users ON clients.id = interests_users.client_id
WHERE interests_users.interest_id = ?", interest.id).each do |user|
Bestevermailer.treatmentNotification(user, #treatment).deliver
end
end
format.html { redirect_to #treatment, notice: 'Treatment was successfully created.' }
format.json { render :show, status: :created, location: #treatment }
else
format.html { render :new }
format.json { render json: #treatment.errors, status: :unprocessable_entity }
end
end
end
Full Trace
activerecord (4.2.5) lib/active_record/connection_adapters/sqlite3_adapter.rb:289:in `exec_query'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/database_statements.rb:355:in `select'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `block in select_all'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/query_cache.rb:83:in `cache_sql'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `select_all'
activerecord (4.2.5) lib/active_record/querying.rb:39:in `find_by_sql'
app/controllers/treatments_controller.rb:72:in `block in create'
actionpack (4.2.5) lib/action_controller/metal/mime_responds.rb:212:in `respond_to'
app/controllers/treatments_controller.rb:68:in `create'
actionpack (4.2.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.5) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.5) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.5) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.5) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.5) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:76:in `call'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:817:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.5) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.5) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.5) lib/rails/engine.rb:518:in `call'
railties (4.2.5) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Try re-framing your query. Here:
User.joins('INNER JOIN interests_users ON clients.id = interests_users.client_id').where("interests_users.interest_id = ?", interest.id)
As per a similar SO:
find_by_sql doesn't work well with query placeholders
find_by_sql expects an array as a parameter:
User.find_by_sql([
"SELECT * FROM users
INNER JOIN interests_users
ON clients.id = interests_users.client_id
WHERE interests_users.interest_id = ?",
interest.id]).each do |user|

How to Get Tags Linkable?

I was using this railscast episode: http://railscasts.com/episodes/382-tagging, which suggested this gem: https://github.com/mbleigh/acts-as-taggable-on,
and all was good to go until I clicked on a User created tag link, which is suppose to then list out every instance of the tag clicked, but instead I got this error message:
SQLite3::SQLException: near "values": syntax error: SELECT "values".* FROM "values" JOIN taggings values_taggings_5183317 ON values_taggings_5183317.taggable_id = values.id AND values_taggings_5183317.taggable_type = 'Value' AND values_taggings_5183317.tag_id = 2
Can you please help me?
# _form
<div class="form-group">
<%= f.text_field :tag_list, class: 'form-control', placeholder: 'Enter Tag(s)' %>
</div>
# Controller
def index
if params[:tag]
#values = Value.tagged_with(params[:tag])
else
#values = Value.order('RANDOM()')
end
end
def value_params
params.require(:value).permit(:name, :tag_list)
end
end
# index
<td class="category">
<b><%= raw value.tag_list.map { |t| link_to t, tag_path(t) }.join(', ') %> </b></td>
# routes
get 'tags/:tag', to: 'values#index', as: :tag
sqlite3 (1.3.10) lib/sqlite3/database.rb:91:in `initialize'
sqlite3 (1.3.10) lib/sqlite3/database.rb:91:in `new'
sqlite3 (1.3.10) lib/sqlite3/database.rb:91:in `prepare'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/sqlite3_adapter.rb:300:in `block in exec_query'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/abstract_adapter.rb:466:in `block in log'
activesupport (4.2.0.rc3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/abstract_adapter.rb:460:in `log'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/sqlite3_adapter.rb:297:in `exec_query'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/abstract/database_statements.rb:336:in `select'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `block in select_all'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/abstract/query_cache.rb:83:in `cache_sql'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `select_all'
activerecord (4.2.0.rc3) lib/active_record/querying.rb:39:in `find_by_sql'
activerecord (4.2.0.rc3) lib/active_record/relation.rb:638:in `exec_queries'
activerecord (4.2.0.rc3) lib/active_record/relation.rb:514:in `load'
activerecord (4.2.0.rc3) lib/active_record/relation.rb:243:in `to_a'
activerecord (4.2.0.rc3) lib/active_record/relation/delegation.rb:46:in `each'
app/views/values/index.html.erb:10:in `_app_views_values_index_html_erb__4435347718394186207_70115274036880'
actionview (4.2.0.rc3) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.0.rc3) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.0.rc3) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.0.rc3) lib/action_view/template.rb:143:in `render'
actionview (4.2.0.rc3) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (4.2.0.rc3) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.0.rc3) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.rc3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.rc3) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.0.rc3) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.0.rc3) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (4.2.0.rc3) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (4.2.0.rc3) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (4.2.0.rc3) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (4.2.0.rc3) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.2.0.rc3) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.2.0.rc3) lib/action_view/rendering.rb:100:in `_render_template'
actionpack (4.2.0.rc3) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.2.0.rc3) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (4.2.0.rc3) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.2.0.rc3) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.0.rc3) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.0.rc3) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.0.rc3) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.2.0.rc3) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/Users/galli01anthony/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
activesupport (4.2.0.rc3) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.0.rc3) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.2.0.rc3) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.2.0.rc3) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.0.rc3) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.2.0.rc3) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.2.0.rc3) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.2.0.rc3) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0.rc3) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0.rc3) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:151:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:151:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0.rc3) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0.rc3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0.rc3) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0.rc3) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.rc3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.rc3) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0.rc3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0.rc3) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0.rc3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0.rc3) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0.rc3) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0.rc3) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0.rc3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0.rc3) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0.rc3) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0.rc3) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0.rc3) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0.rc3) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0.rc3) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0.rc3) lib/action_dispatch/routing/route_set.rb:802:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0.rc3) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0.rc3) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0.rc3) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0.rc3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0.rc3) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0.rc3) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0.rc3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0.rc3) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0.rc3) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0.rc3) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0.rc3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0.rc3) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0.rc3) lib/rails/engine.rb:518:in `call'
railties (4.2.0.rc3) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
/Users/galli01anthony/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/galli01anthony/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/galli01anthony/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Thanks in advance!!!
I think the problem is twofold.
The token "values" is a reserved word in standard SQL. As insert into table_name values (...);.
You use it without double quotes, which are required in standard SQL for reserved words used as identifiers. (Better not to use reserved words that way, but still . . .) MySQL isn't standard; it uses backticks. SQL Server uses square brackets.
You need to quote values.id.
SELECT "values".*
FROM "values"
JOIN taggings values_taggings_5183317
ON values_taggings_5183317.taggable_id = "values".id
-- ^ ^
AND values_taggings_5183317.taggable_type = 'Value'
AND values_taggings_5183317.tag_id = 2

Can't figure out how to rescue ActiveRecord::StatementInvalid error in Rails

I'm using Postgres full-text search and when someone types in a query that's unquery-able, I can't seem to rescue that error. Here's the error I'll get for an example:
Started GET "/products/search?query=asd+()" for 127.0.0.1 at 2014-02-04 07:46:52 -0600
Processing by ProductsController#search as JSON
Parameters: {"query"=>"asd ()"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1364 LIMIT 1
Account Load (0.6ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = 2051 LIMIT 1
Product Load (4.0ms) SELECT id, brand, style_description, style_number, price_per FROM "products" WHERE (to_tsvector('english', style_description) ## to_tsquery('asd & ():*') or to_tsvector('english', style_number) ## to_tsquery('asd & ():*') or to_tsvector('english', brand) ## to_tsquery('asd & ():*')) AND (account_id = 2051) LIMIT 8
PG::SyntaxError: ERROR: syntax error in tsquery: "asd & ():*"
: SELECT id, brand, style_description, style_number, price_per FROM "products" WHERE (to_tsvector('english', style_description) ## to_tsquery('asd & ():*') or to_tsvector('english', style_number) ## to_tsquery('asd & ():*') or to_tsvector('english', brand) ## to_tsquery('asd & ():*')) AND (account_id = 2051) LIMIT 8
Completed 500 Internal Server Error in 443ms
ActiveRecord::StatementInvalid - PG::SyntaxError: ERROR: syntax error in tsquery: "asd & ():*"
: SELECT id, brand, style_description, style_number, price_per FROM "products" WHERE (to_tsvector('english', style_description) ## to_tsquery('asd & ():*') or to_tsvector('english', style_number) ## to_tsquery('asd & ():*') or to_tsvector('english', brand) ## to_tsquery('asd & ():*')) AND (account_id = 2051) LIMIT 8:
activerecord (3.2.14) lib/active_record/connection_adapters/abstract_adapter.rb:285:in `rescue in log'
activerecord (3.2.14) lib/active_record/connection_adapters/abstract_adapter.rb:280:in `log'
newrelic_rpm (3.7.1.188) lib/new_relic/agent/instrumentation/active_record.rb:46:in `block in log_with_newrelic_instrumentation'
newrelic_rpm (3.7.1.188) lib/new_relic/agent/method_tracer.rb:276:in `trace_execution_scoped'
newrelic_rpm (3.7.1.188) lib/new_relic/agent/instrumentation/active_record.rb:43:in `log_with_newrelic_instrumentation'
activerecord (3.2.14) lib/active_record/connection_adapters/postgresql_adapter.rb:659:in `exec_query'
activerecord (3.2.14) lib/active_record/connection_adapters/postgresql_adapter.rb:1262:in `select'
activerecord (3.2.14) lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
activerecord (3.2.14) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `block in select_all'
activerecord (3.2.14) lib/active_record/connection_adapters/abstract/query_cache.rb:75:in `cache_sql'
activerecord (3.2.14) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `select_all'
activerecord (3.2.14) lib/active_record/querying.rb:38:in `block in find_by_sql'
activerecord (3.2.14) lib/active_record/explain.rb:41:in `logging_query_plan'
activerecord (3.2.14) lib/active_record/querying.rb:37:in `find_by_sql'
newrelic_rpm (3.7.1.188) lib/new_relic/agent/method_tracer.rb:524:in `block in find_by_sql_with_trace_ActiveRecord_self_name_find_by_sql'
newrelic_rpm (3.7.1.188) lib/new_relic/agent/method_tracer.rb:276:in `trace_execution_scoped'
newrelic_rpm (3.7.1.188) lib/new_relic/agent/method_tracer.rb:519:in `find_by_sql_with_trace_ActiveRecord_self_name_find_by_sql'
activerecord (3.2.14) lib/active_record/relation.rb:171:in `exec_queries'
activerecord (3.2.14) lib/active_record/relation.rb:160:in `block in to_a'
activerecord (3.2.14) lib/active_record/explain.rb:41:in `logging_query_plan'
activerecord (3.2.14) lib/active_record/relation.rb:159:in `to_a'
bullet (4.7.1) lib/bullet/active_record3x.rb:10:in `to_a'
activerecord (3.2.14) lib/active_record/relation.rb:198:in `as_json'
activesupport (3.2.14) lib/active_support/json/encoding.rb:47:in `block in encode'
activesupport (3.2.14) lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
activesupport (3.2.14) lib/active_support/json/encoding.rb:46:in `encode'
activesupport (3.2.14) lib/active_support/json/encoding.rb:31:in `encode'
activesupport (3.2.14) lib/active_support/core_ext/object/to_json.rb:16:in `to_json'
app/controllers/products_controller.rb:7:in `search'
actionpack (3.2.14) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.14) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.14) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.14) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.14) lib/active_support/callbacks.rb:447:in `_run__70639927732585872__process_action__2788875327411416872__callbacks'
activesupport (3.2.14) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.14) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.14) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.14) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.14) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.14) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.14) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.14) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.14) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.14) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.14) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.14) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
newrelic_rpm (3.7.1.188) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:38:in `block in process_action'
newrelic_rpm (3.7.1.188) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:339:in `perform_action_with_newrelic_trace'
newrelic_rpm (3.7.1.188) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:37:in `process_action'
actionpack (3.2.14) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.14) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.14) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.14) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.14) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.14) 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 `call'
actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:608:in `call'
newrelic_rpm (3.7.1.188) lib/new_relic/rack/error_collector.rb:50:in `call'
newrelic_rpm (3.7.1.188) lib/new_relic/rack/agent_hooks.rb:28:in `call'
newrelic_rpm (3.7.1.188) lib/new_relic/rack/browser_monitoring.rb:23:in `call'
newrelic_rpm (3.7.1.188) lib/new_relic/rack/developer_mode.rb:42:in `call'
meta_request (0.2.8) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
meta_request (0.2.8) lib/meta_request/middlewares/headers.rb:16:in `call'
meta_request (0.2.8) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
bullet (4.7.1) lib/bullet/rack.rb:12:in `call'
rack-cors (0.2.9) lib/rack/cors.rb:54:in `call'
oink (0.10.1) lib/oink/middleware.rb:17:in `call'
rack-openid (1.4.2) lib/rack/openid.rb:98:in `call'
rack (1.4.5) lib/rack/deflater.rb:13:in `call'
client_side_validations (3.2.6) lib/client_side_validations/middleware.rb:17:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.14) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.14) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.14) lib/active_support/callbacks.rb:405:in `_run__2432337498521717412__call__41636529287313326__callbacks'
activesupport (3.2.14) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.14) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.14) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.14) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
rails-dev-tweaks (1.1.0) lib/rails_dev_tweaks/granular_autoload/middleware.rb:34:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
airbrake (3.1.15) lib/airbrake/rails/middleware.rb:13:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.14) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.14) lib/rails/rack/logger.rb:18:in `call'
quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
actionpack (3.2.14) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.14) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/static.rb:63:in `call'
airbrake (3.1.15) lib/airbrake/user_informer.rb:16:in `_call'
airbrake (3.1.15) lib/airbrake/user_informer.rb:12:in `call'
railties (3.2.14) lib/rails/engine.rb:484:in `call'
railties (3.2.14) lib/rails/application.rb:231:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.14) lib/rails/rack/log_tailer.rb:17:in `call'
thin (1.6.1) lib/thin/connection.rb:82:in `block in pre_process'
thin (1.6.1) lib/thin/connection.rb:80:in `pre_process'
thin (1.6.1) lib/thin/connection.rb:55:in `process'
thin (1.6.1) lib/thin/connection.rb:41:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.6.1) lib/thin/backends/base.rb:73:in `start'
thin (1.6.1) lib/thin/server.rb:162:in `start'
rack (1.4.5) lib/rack/handler/thin.rb:13:in `run'
rack (1.4.5) lib/rack/server.rb:268:in `start'
railties (3.2.14) lib/rails/commands/server.rb:70:in `start'
railties (3.2.14) lib/rails/commands.rb:55:in `block in <top (required)>'
railties (3.2.14) lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `<main>'
Here's my code:
def self.text_search(query, account)
uncached do
if query.present?
begin
query = query.split(" ").join(" & ")
if account.use_global_products?
where("to_tsvector('english', style_description) ## to_tsquery(:q) or to_tsvector('english', style_number) ## to_tsquery(:q) or to_tsvector('english', brand) ## to_tsquery(:q)", q: "#{query.strip}:*").where("account_id = ? OR account_id = ?", 0, account.id)
else
where("to_tsvector('english', style_description) ## to_tsquery(:q) or to_tsvector('english', style_number) ## to_tsquery(:q) or to_tsvector('english', brand) ## to_tsquery(:q)", q: "#{query.strip}:*").where("account_id = ?", account.id)
end
rescue Exception => error
puts "inspect it #{error.inspect}"
end
else
scoped
end
end
end
Any idea why ActiveRecord::StatementInvalid still isn't rescuing?
EDIT
This looks like it has to do with when the query is actually evaluated. You're returning the chained query, but it's likely being first executed in your controller, since you're not returning the actual results of the query with your method.
So you could either rescue in the controller, or you could go ahead and evaluate the query in your method and then return the object you want.
Also note that it's not a great idea to rescue Exception in Ruby. See
Why is it a bad style to `rescue Exception => e` in Ruby? for more
You don't need to structure it the way you have (begin/rescue/end); you can rescue off the entire method failing instead:
def self.text_search(query)
uncached do
if query.present?
query = query.split(" ").join(" & ")
where("to_tsvector('english', style_description) ## to_tsquery(:q) or to_tsvector('english', style_number) ## to_tsquery(:q) or to_tsvector('english', brand) ## to_tsquery(:q)", q: "#{query.strip}:*").where("account_id = ? OR account_id = ?", 0, account.id)
else
scoped
end
end
rescue ActiveRecord::StatementInvalid => error
puts "Search Error"
end
Here is the code (using rails 4.0.1 here) in abstract_adapter.rb that handles the output to log (inside log method)
rescue => e
message = "#{e.class.name}: #{e.message}: #{sql}"
#logger.error message if #logger
exception = translate_exception(e, message)
exception.set_backtrace e.backtrace
raise exception
end
Looks like as long as #logger is active activerecord will always report this to the log file.
I wish there was a way to avoid this kind of behaviour when rescuing externally, so any ideas would be welcome.
I had a similar issue in one of my projects. I was able to rescue the error thanks to #Tyler's answer.
I'm using Rails 5.2.3. In my database there is a table, Movie, with one column called title in it.
(Please forgive the use of eval, I know you it's bad practice to use it.)
begin
result = eval("Movie.where(name: \"test\")")
p result # this actually triggers the SQL error
rescue ActiveRecord::StatementInvalid => error_variable
p "We got 'em"
result = error_variable.to_s
end
So in short, you can't just run the query in the begin block, you also need to evaluate it. This can be done with a simple p statement of the query result.

Devise + OmniAuth NoMethodError UndefinedMethod Username

I'm following through Railscast #235 "Devise + OmniAuth Revised" and have run into a NoMethodError for Username whenever I try to authenticate using Twitter. I'm running Rails 3.2.
Specifically, it reads:
NoMethodError in OmniauthCallbacksController#twitter
undefined method `username' for #<User:0x007fa4744561c0>
app/models/user.rb:11:in `from_omniauth'
app/controllers/omniauth_callbacks_controller.rb:3:in `all'
I'm new to Rails, so any help would be much appreciated. Here's a look at my code:
The omniauth_callbacks_controller:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def all
user = User.from_omniauth(request.env["omniauth.auth"])
if user.persisted?
flash.notice = "Signed in!"
sign_in_and_redirect user
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
alias_method :twitter, :all
end
The user model:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :username
validates_presence_of :username
validates_uniqueness_of :username
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname
end
end
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
def password_required?
super && provider.blank?
end
def update_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
else
super
end
end
end
Framework Trace:
activemodel (3.2.8) lib/active_model/attribute_methods.rb:407:in `method_missing'
activerecord (3.2.8) lib/active_record/attribute_methods.rb:149:in `method_missing'
activemodel (3.2.8) lib/active_model/errors.rb:254:in `block in add_on_blank'
activemodel (3.2.8) lib/active_model/errors.rb:253:in `each'
activemodel (3.2.8) lib/active_model/errors.rb:253:in `add_on_blank'
activemodel (3.2.8) lib/active_model/validations/presence.rb:8:in `validate'
activesupport (3.2.8) lib/active_support/callbacks.rb:310:in `_callback_before_35'
activesupport (3.2.8) lib/active_support/callbacks.rb:473:in `_run__3967236747236009763__validate__2888041296400006394__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
activemodel (3.2.8) lib/active_model/validations.rb:227:in `run_validations!'
activemodel (3.2.8) lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
activesupport (3.2.8) lib/active_support/callbacks.rb:425:in `_run__3967236747236009763__validation__2888041296400006394__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
activemodel (3.2.8) lib/active_model/validations/callbacks.rb:53:in `run_validations!'
activemodel (3.2.8) lib/active_model/validations.rb:194:in `valid?'
activerecord (3.2.8) lib/active_record/validations.rb:69:in `valid?'
activerecord (3.2.8) lib/active_record/validations.rb:77:in `perform_validations'
activerecord (3.2.8) lib/active_record/validations.rb:50:in `save'
activerecord (3.2.8) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (3.2.8) lib/active_record/transactions.rb:241:in `block (2 levels) in save'
activerecord (3.2.8) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.2.8) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.2.8) lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
activerecord (3.2.8) lib/active_record/transactions.rb:241:in `block in save'
activerecord (3.2.8) lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
activerecord (3.2.8) lib/active_record/transactions.rb:240:in `save'
activerecord (3.2.8) lib/active_record/persistence.rb:45:in `create'
activerecord (3.2.8) lib/active_record/relation.rb:87:in `block in create'
activerecord (3.2.8) lib/active_record/relation.rb:241:in `block in scoping'
activerecord (3.2.8) lib/active_record/scoping.rb:98:in `with_scope'
activerecord (3.2.8) lib/active_record/relation.rb:241:in `scoping'
activerecord (3.2.8) lib/active_record/relation.rb:87:in `create'
activerecord (3.2.8) lib/active_record/relation.rb:119:in `first_or_create'
actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.8) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.8) lib/active_support/callbacks.rb:436:in `_run__3199821227742357635__process_action__2555454004410598156__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.8) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.8) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.8) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:36:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/mapper.rb:42: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.8) lib/action_dispatch/routing/route_set.rb:600:in `call'
omniauth (1.1.1) lib/omniauth/strategy.rb:394:in `call_app!'
omniauth (1.1.1) lib/omniauth/strategy.rb:356:in `callback_phase'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:58:in `callback_phase'
omniauth (1.1.1) lib/omniauth/strategy.rb:219:in `callback_call'
omniauth (1.1.1) lib/omniauth/strategy.rb:175:in `call!'
omniauth (1.1.1) lib/omniauth/strategy.rb:157: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.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/cookies.rb:339:in `call'
activerecord (3.2.8) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `_run__635784344197953786__call__2888041296400006394__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
thin (1.4.1) lib/thin/connection.rb:80:in `block in pre_process'
thin (1.4.1) lib/thin/connection.rb:78:in `catch'
thin (1.4.1) lib/thin/connection.rb:78:in `pre_process'
thin (1.4.1) lib/thin/connection.rb:53:in `process'
thin (1.4.1) lib/thin/connection.rb:38:in `receive_data'
eventmachine (1.0.0) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.0) lib/eventmachine.rb:187:in `run'
thin (1.4.1) lib/thin/backends/base.rb:63:in `start'
thin (1.4.1) lib/thin/server.rb:159:in `start'
rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
rack (1.4.1) lib/rack/server.rb:265:in `start'
railties (3.2.8) lib/rails/commands/server.rb:70:in `start'
railties (3.2.8) lib/rails/commands.rb:55:in `block in <top (required)>'
railties (3.2.8) lib/rails/commands.rb:50:in `tap'
railties (3.2.8) lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
You need to add a username column to your users table.

delayed_job: undefined method `name' for nil:NilClass

I just installed delayed job on my little Rails 3.2 app. Here is the controller where I use it:
require 'waveform'
class MixesController < ApplicationController
def index
end
def new
#mix = Mix.new
end
def create
#mix = Mix.new(params[:mix])
if #mix.save
options = {
method: :rms,
width: 1800,
height: 280,
background_color: "#ffffff",
color: "#3333ff",
force: true,
quiet: true
}
waveform = "./public/waveforms/#{File.basename(#mix.sound_file.to_s, File.extname(#mix.sound_file.to_s))}.png"
::Waveform.new("./public" + #mix.sound_file.to_s, nil).delay.generate(waveform, options)
flash[:success] = "Mix successfully uploaded"
redirect_to mix_url(#mix)
else
render :new
end
end
def show
#mix = Mix.find(params[:id])
end
end
I get an error saying: undefined methodname' for nil:NilClass`, here is the full stack trace:
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:25:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:447:in `block in dump_ivars'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:445:in `each'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:445:in `dump_ivars'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:124:in `visit_Object'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:434:in `block in emit_coder'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:432:in `each'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:432:in `emit_coder'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:417:in `dump_coder'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:100:in `accept'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:66:in `push'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:242:in `dump'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/core_ext.rb:14:in `psych_to_yaml'
delayed_job (3.0.3) lib/delayed/backend/base.rb:80:in `payload_object='
activerecord (3.2.3) lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
activerecord (3.2.3) lib/active_record/attribute_assignment.rb:78:in `each'
activerecord (3.2.3) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
activerecord (3.2.3) lib/active_record/base.rb:498:in `initialize'
delayed_job (3.0.3) lib/delayed/backend/base.rb:28:in `new'
delayed_job (3.0.3) lib/delayed/backend/base.rb:28:in `enqueue'
delayed_job (3.0.3) lib/delayed/message_sending.rb:13:in `method_missing'
app/controllers/mixes_controller.rb:25:in `create'
actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.3) lib/active_support/callbacks.rb:414:in `_run__842168672059661955__process_action__4066633601342968686__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.3) lib/journey/router.rb:68:in `block in call'
journey (1.0.3) lib/journey/router.rb:56:in `each'
journey (1.0.3) lib/journey/router.rb:56:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:35: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.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200: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__647780415925652457__call__1911592835196459847__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'
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.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) 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.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.3) lib/rails/engine.rb:479:in `call'
railties (3.2.3) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Does anyone know why I am getting this error please?
This is happening because the system is trying to turn nil into a value that can be stored in YAML and is failing.
Looking at your code, I expect that is because you are passing a nil object into the variables passed to Waveform.new (the method whose operation is being delayed). The variables passed to new will need to be stored until delayed job is ready to run the process, and I expect they are stored as YAML.
Can you refactor Waveform to either make the second attribute optional (so its value doesn't have to be preserved)
::Waveform.new("./public" + #mix.sound_file.to_s).delay.generate(waveform, options)
or use something else to have the same meaning as nil. For example, pass in the symbol :none. Then the line becomes:
::Waveform.new("./public" + #mix.sound_file.to_s, :none).delay.generate(waveform, options)