What I am trying to do is basically have an auto complete for a text box... the js is working properly but, I keep running into this same error with active record and oracle ruby-oci8. Any help would be greatly appreciated.
This is the error
ActiveRecord::StatementInvalid (OCIError: ORA-00904: "'SNOWJ'": invalid ide ntifier: SELECT "EMPLOYEE".* FROM "EMPLOYEE" WHERE ( emp_id like "'SNOWJ'" )):
app/controllers/user_controller.rb:7:in `emp_id_autocomplete'
This is my Visual model
class Visual < ActiveRecord::Base
establish_connection :vtest
self.table_name = 'employee'
belongs_to :user
scope :search_id, lambda {|id|
where(%q{ emp_id like "?" }, id)
}
end
This is my user model
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :emp_id,
This is my user controller
class UserController < ApplicationController
def emp_id_autocomplete
@query = params[:term]
@json = Visual.search_id(@query).collect {|e| e.id}.uniq
respond_to do |format|
format.js { render :json => @json.to_json, :layout => false }
end
end
end
This is my view
<div class='row form-group'>
<div class='col-xs-8 col-xs-offset-2 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4 col-lg-2 col-lg-offset-5 text-right'>
<%= f.text_field :emp_id, tabindex: 1, id: 'emp_id', autofocus: true, placeholder: t( 'login_label' ), class: 'form-control' %>
</div>
</div>
This is my routes .
Rails.application.routes.draw do
# Routes for devise user authentication
devise_for :users, controllers: { sessions: 'sessions' }
root to: 'entry#index'
resources :entry do
end
resources :user do
collection do
get :emp_id_autocomplete
end
end
This is my app.js
//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require best_in_place
//= require bootstrap
//= require jquery.ui.datepicker
//= require moment.js
//= require fullcalendar
//= require daterangepicker.js
//= require entry
//= require user
$(function() {
$("#emp_id").autocomplete({
source: "user/emp_id_autocomplete",
minLength: 3
});
});
These are my tables User table has emp_id and Visual model is acutually called employee table and has id. what I want the auto complete to do is looks at the emp_id text box then looks in employee table for an id that matches or is close to matching if possible...
User model table
create_table "users"
t.string "emp_id"
t.datetime "created_at"
t.datetime "updated_at"
Visual model table
create_table "employee"
t.string "id"
t.datetime "created_at"
t.datetime "updated_at"
I think you have an error in quotes, try to replace:
where(%q{ emp_id like "?" }, id)
with
where("emp_id like ?", id)