When i performance a search with Yourub gem configuration for a youtube video search, the server console returns me the following error message:
Completed 500 Internal Server Error in 7ms
NameError (uninitialized constant ExploreController::Yourub):
app/controllers/explore_controller.rb:18:in `search'
Added config/yourub.yml as showed on the gem site
https://github.com/edap/yourub
On the explore_controller file we can find this:
class ExploreController < ApplicationController
def index
...
end
def search
if params[:queryType] == "users"
...
elsif params[:queryType] == "tracks"
client = Yourub::Client.new
client.search(query: params[:queryField]) do |v|
puts v
end
return redirect_to('/explore')
else
return redirect_to('/explore')
end
end
end
Also added my yourub.yml file here:
yourub_defaults: &yourub_defaults
developer_key: 'apiKey'
youtube_api_service_name: 'youtube'
youtube_api_version: 'v3'
application_name: "apiAplicationName"
application_version: "0.1"
log_level: WARN
development:
<<: *yourub_defaults
production:
<<: *yourub_defaults
test:
<<: *yourub_defaults
Restart the server. That should fix the issue.
Related
This is my routes.rb
namespace :api do
get 'suggestions/jobs', to: "suggestions#jobs"
end
My controller
class Api::SuggestionsController < ApplicationController
def jobs
#jobs = Job.job_title_search(params[:q]) #.select(:title, :label).distinct
if #jobs.present?
render json: #jobs, status: :ok
else
render json: "Not Found", status: :ok
end
end
end
and model
def self.job_title_search(q)
where('title LIKE ?', "%#{q}%").select(:title, :label).distinct
end
in the development environment like localhost:3000/api/suggestions/jobs?q=dev the data sample is
[
{"id":null,"title":"React Native Developer","label":"Top label job"},
{"id":null,"title":"Android Developer","label":"Top label job"},
{"id":null,"title":"Business Development Representative","label":"Mid label job"},
{"id":null,"title":"Node.js Developer","label":"Top label job"}
]
that means it's working, but while I pushed into the Heroku then like example.herokuapp.com/api/suggestions/jobs?q=dev it's showing
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
I know there is "Not Found" like the code is
render json: "Not Found", status: :ok
My question is why same code is not working on Heroku? and What can I do for this?
the database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: my_project_production
username: my_project
password: <%= ENV['MY_PROJECT_DATABASE_PASSWORD'] %>
Any help appriciated.
Thanks
The if branch of your code is fine, and since dev contains records, it’s being rendered without any glitch.
In prod, OTOH, there are no records and the else branch, which is not quite correct, is tried to be rendered. And it fails, giving you the error.
Do supply a hash there instead:
else
render json: {error: "Not Found"}, status: :ok
end
Look the LIKE keyword in SQL, if you use SQLite database for development and PostgreSQL database for production then maybe it's happened, the like is working on the development environment and production environment will be ilike the like does not work, OTOH, ilike does not work in SQLite.
If so then the solution is:
Solution 1 You can change the development database to PostgreSQL, if you have worry about changing the database then follow the below
Solution 2 You can use lower(attr) like
def self.job_title_search(q)
where('lower(title) LIKE lower(?)', "%#{q}%").select(:title, :label).distinct
end
You can see the SO Answer for this.
Hope will help.
Issue is with broadcasting data through a web socket using ActionCable. The error seems to suggest its coming from the create method.
Error Message
Rendered weight/_weight.html.erb (1.1ms)
[ActionCable] Broadcasting to weight: "<div class=\"row\">\n <div class=\"col-md-8 well\">\n <p>12.0 kg</p>\n <small>less than a minute</small>\n </div>\n</div>"
Completed 500 Internal Server Error in 25ms (Views: 7.4ms | ActiveRecord: 10.6ms)
NoMethodError (undefined method `fetch' for nil:NilClass):
app/controllers/weight_controller.rb:7:in `create'
Rendering /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb
Rendering /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_source.text.erb
Rendered /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_source.text.erb (0.8ms)
Rendering /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb
Rendered /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (0.9ms)
Rendering /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb
Rendered /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (1.1ms)
Rendered /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb (25.0ms)
Create method from controller.rb
def create
#weight = Weight.new(weight_params)
#weight.user_id = current_user.id
if #weight.save
ActionCable.server.broadcast "weight", render(partial: 'weight/weight', object: #weight)
else
flash[:danger] = "New Weight was not added!"
redirect_to current_user
end
end
private
def weight_params
params.require(:weights).permit(:weight)
end
I just cant work out what is returned as nil. The fact that the info is correct in what it is broadcasting to weight is correct suggests it has saves it correctly to the database. Can't think what else it is performing the 'fetch' method on.
Pretty sure the web socket is set up correctly. See below.
config/application.rb :
config.action_cable.mount_path = '/cable'
config/routes.rb :
mount ActionCable.server => '/cable'
weight_channel.rb :
def subscribed
stream_from "weight"
end
weight.coffee :
received: (data) ->
$("#messages").prepend(data)
The error was raised due to a missing config/cable.yml file.
The solution was to use a config/cable.yml with the required setting for the application. i.e.:
# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket.
production:
adapter: redis
url: redis://localhost:6379/1
development:
adapter: redis
url: redis://localhost:6379/1
staging:
adapter: redis
url: redis://localhost:6379/1
test:
adapter: async
The resolution appears in the question's comments.
First, I do really apologize, since I'm still newbie on this.
I was trying to install Fat Free CRM by following the instruction on this following sites:
http://www.blogdugeek.fr/crm-installation-fat-free-crm-debian-squeeze/
http://guides.fatfreecrm.com/Setup-Linux-or-Mac-OS.html
As I follow the instructions, I've encounter some errors and resolved some. However, upon executing this command:
RAILS_ENV=production rake db:create db:migrate crm:settings:load
I was stuck in this command line and here are the following errors that I've been stuck with:
rake aborted!
NoMethodError: undefined method `each' for #<String:0x00000003a27a58>
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:150:in `resolve_all'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:69:in `resolve'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/core.rb:46:in `configurations='
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/railties/databases.rake:5:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)
As I've search for more related issue, I found some, but it's still no use.
Also, here are some data that might be needed:
Ruby Version
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
Rails Version
Rails 4.2.6
Here are the error lines
connection_specification.rb
def resolve(config)
if config
resolve_connection config
elsif env = ActiveRecord::ConnectionHandling::RAILS_ENV.call
resolve_symbol_connection env.to_sym
else
raise AdapterNotSpecified
end
end
# Expands each key in #configurations hash into fully resolved hash
def resolve_all
config = configurations.dup
config.each do |key, value| <---- Error line
config[key] = resolve(value) if value
end
config
end
connection_handling.rb
class MergeAndResolveDefaultUrlConfig # :nodoc:
def initialize(raw_configurations)
#raw_config = raw_configurations.dup
#env = DEFAULT_ENV.call.to_s
end
# Returns fully resolved connection hashes.
# Merges connection information from `ENV['DATABASE_URL']` if available.
def resolve
Error line ----> ConnectionAdapters::ConnectionSpecification::Resolver.new(config).resolve_all
end
private
def config
#raw_config.dup.tap do |cfg|
if url = ENV['DATABASE_URL']
cfg[#env] ||= {}
cfg[#env]["url"] ||= url
end
end
end
core.rb
def self.configurations=(config)
Error line ---> ##configurations = ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig.new(config).resolve
end
self.configurations = {}
# Returns fully resolved configurations hash
def self.configurations
##configurations
end
databases.rake
db_namespace = namespace :db do task :load_config do
Error line ----> ActiveRecord::Base.configurations = ActiveRecord::Tasks::DatabaseTasks.database_configuration || {}
ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
Here's the config/database.yml file.
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
#------------------------------------------------------------------------------
development:&development
adapter:mysql2
encoding:utf8
database:fat_free_crm_development
pool:5
username:root
# password:
socket:/var/run/mysqld/mysqld.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *development
database: fat_free_crm_test
production:
adapter: mysql
encoding: utf8
database: fat_free_crm_production
pool: 5
username: root
password:
socket: /var/run/mysqld/mysqld.sock
socket: /tmp/mysql.sock
staging:
<<: *development
database: fat_free_crm_staging
Hope to hear and seek some advises and learning.
If there's need some more information, let me know.
Thanks,
Your database.yml is the problem. YAML requires a separator between the key and data.
So not like this:
production:
adapter:mysql
encoding:utf8
...
But like this:
production:
adapter: mysql
encoding: utf8
...
You need to correct all the lines in the file, because you have this error everywhere.
Check the database.yml file again. Don't add anything
ie the file format must be correct.
had unkowngly comment a line on to that was causing the error.
Im trying to store my api key in a yaml file
fresh_desk.yml
production:
:api_key: 12345
staging:
:api_key: 12345
development:
:api_key: my api key here
then in my lib folder i have a file called
fresh_desk_api_wrapper.rb
class FreshDeskApiWrapper
attr_accessor :config, :client
def initialize
self.config = YAML.load("#{Rails.root}/config/fresh_desk.yml")[Rails.env]
self.client = Freshdesk.new("http://onehouse.freshdesk.com/", config.api_key, "X")
end
def post_tickets(params)
client.post_tickets(params)
end
end
then in my
clients_controller.rb
def create
FreshDeskApiWrapper.new().post_tickets(params[:client])
redirect_to new_client_path
end
but when i submit my form i get an error
undefined method `api_key' for nil:NilClass
does anyone know whats causing this? and how to fix it?
you might need a File.open
blah.yml
production:
:api_key: 12345
staging:
:api_key: 45678
development:
:api_key: 10203
Then you can load it into a hash
>> require 'yaml'
=> true
>> config = YAML::load(File.open('blah.yml'))
=> {"production"=>{:api_key=>12345}, "staging"=>{:api_key=>45678}, "development"=>{:api_key=>10203}}
I am trying to use different stripe keys (a credit card payment processing system) depending on whether I'm in test/development or production/ Based on suggestions I've seen on StackOverflow, I did the following:
In my /config/initalizers/stripe.rb file, I have the following:
STRIPE_CONFIG = begin
config = YAML.load(File.open(Rails.root.join('config', 'stripe.yml')))
config = config[Rails.env] || {}
config.to_options
end
and in my /config/stripe.yml file, I have the following:
default: &default
Stripe.api_key: "testapikeycode"
STRIPE_PUBLIC_KEY: "testpublickeycode"
development:
<<: *default
test:
<<: *default
production:
Stripe.api_key: "productionapikeycode"
STRIPE_PUBLIC_KEY: "productionpublickeycode"
However, when I go into the console (rails console), and I type
puts STRIPE_PUBLIC_KEY
I get the following error message:
NameError: uninitialized constant STRIPE_PUBLIC_KEY
Any ideas?
Alternate method
Only use stripe.rb, and have the following in it:
if Rails.env == 'production'
Stripe.api_key: "productionapikeycode"
STRIPE_PUBLIC_KEY: "productionpublickeycode"
else
Stripe.api_key: "tesapikeycode"
STRIPE_PUBLIC_KEY: "testpublickeycode"
end
STRIPE_PUBLIC_KEY is a key in your yaml config file, you never actually initialize it as a constant. If you type p STRIPE_CONFIG['STRIPE_PUBLIC_KEY'] instead you should get the result you want.
Aside I think YAML.load should be YAML.load_file.