PG syntax error - ruby-on-rails

I've been trying to convert the fedena project built on ruby on rails for my school from mySQL to postgreSQL for heroku deployment and ran into the following error:
Showing app/views/class_timings/index.html.erb where line #40 raised:
PG::Error: ERROR: syntax error at or near "."
LINE 1: SELECT `batches`.*,CONCAT(courses.code,'-',batches.name) as ...
^
: SELECT `batches`.*,CONCAT(courses.code,'-',batches.name) as course_full_name FROM "batches" INNER JOIN "courses" ON "courses".id = "batches".course_id WHERE ("batches"."is_deleted" = 'f' AND "batches"."is_active" = 't') ORDER BY course_full_name
Extracted source (around line #40):
37: <label ><%= t('select_a_batch') %>:</label>
38: <div class="text-input-bg">
39: <%= select :batch, :id,
40: #batches.map {|b| [b.full_name, b.id] },
41: {:prompt => "#{t('common')}"},
42: {:onchange => "#{remote_function(
43: :url => { :action => 'show' },
44: :with => "'batch_id='+value",
45: :before => "Element.show('loader')",
46: :success => "Element.hide('loader')"
47: )}"} %>
Obviously, I'm new to programming! Please help.
The controller:
class_timings_controller.rb
def index
#batches = Batch.active
#class_timings = ClassTiming.find(:all,:conditions => { :batch_id => nil,:is_deleted=>false}, :order =>'start_time ASC')
end

Both the backtick quotes ` and the CONCAT function are non-standard SQL.
If you really want to quote table-names you'll need to use double-quotes. There is a text-concatenation operator you'll want in Postgresql called ||.
So you'll have something like:
SELECT "batches".*, (courses.code || '-' || "batches"."name") as course_full_name ...
Be consistent - if you are quoting tables names in some places, quote them everywhere.
This is going to be slow going until you understand the syntax of both databases at at least a basic level. Presumably there's not too much raw SQL since you're using rails though.
Tip: set aside a couple of hours and skim through the manuals of both systems. At least you'll know where to look to check details then.

Related

syntax error, unexpected keyword_ensure, expecting end-of-input in line 61 - haml

I am working in the following code. It is from the project 8agentball available in github (https://github.com/thinkpixellab/agent8ball).
I am a beginner in Ruby and Rails(started learning today), and I get an error when I try to execute it. I searched in the internet for over 4 hours and did not find anything.
- uncompiled = Rails.env == 'development' && params.has_key?('uncompiled')
- content_for :header do
= game_js(uncompiled)
%link{:rel => 'canonical', :href => 'http://agent8ball.com'}
%a#fork_me{:href => "https://github.com/thinkpixellab/agent8ball"}
%img{:alt => "Fork me on GitHub", :src => "http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"}
- if Rails.env == 'development'
- if(uncompiled)
= link_to "Uncompiled", root_path, :id => 'debug', :title => 'Go to compiled version'
- else
= link_to "Compiled", '/?uncompiled', :id => 'debug', :title => 'Go to uncompiled version'
And I get this error:
Showing
/Users/user/Documents/61/v4/agent8ball-master/app/views/main/index.haml
where line #xx raised:
/Users/user/Documents/61/v4/agent8ball-master/app/views/main/index.haml:xx: syntax error, unexpected keyword_ensure, expecting end-of-input
I tried indenting code, tried putting - end after if/else and/or do but to no use.
Any idea?
Thank you

Using DBRef in mongo ruby driver: (undefined method `bson_type' for #<Mongo::DBRef:0x0056466ed55e48>)

When I try to use DBRef in the mongo ruby driver (creating a new DBRef object and including in a document which I am inserting into a collection), I get this error that I cannot make heads nor tails of:
NoMethodError (undefined method `bson_type' for #<Mongo::DBRef:0x0056466ed55e48>):
app/controllers/payment_notifications_controller.rb:43:in `block in create'
app/controllers/payment_notifications_controller.rb:19:in `create'
Here is the code in question:
user_mongo = Urgent::Application.config.mongo_client[:user].find(uuid: order.identity.uuid)
if user_mongo
grant_document = { :target => Mongo::DBRef.new("user", user_mongo.first["_id"]), :role => order_item.expirable.backend_id, :created => Time.now, :store_item_id => order_item.id, :store_order_id => order.id }
if expires
grant_document[:expires] = expires
end
Urgent::Application.config.mongo_client[:grant].insert_one(grant_document)
end
Line 39 refers to the second to last line in the code snippet.
The Ruby Mongo driver (I am using v2.2.0) does not define a bson_type method on the Mongo::DBRef class. I was able to work around this particular limitation by specifying the DB reference as extended JSON (link). Define your grant_document hash as:
grant_document = { :target => { "$ref" => "user", "$id" => user_mongo.first["_id"] }, :role => ... }

Error RequestURITooLarge searching ruby

Here the thing: I have multiples search fields in my form. But i got the error RequestURITooLarge when I tried to do a multiples searches...I'm wondering if it is exist a method to avoid this problem. Every time you fill the text box or date field increment the url and got the error. I also tried a reset button but just clean the text fields. Here the code for you to understand the method I use and perhaps will help you in some way. Tks!!
View_item
def self.search(s_codigo, s_den_cont, s_marca)
where("codigo ilike :s_c and den_cont ilike :s_d and marca ilike :s_m", s_c: "%#{s_codigo}%", s_d: "%#{s_den_cont}%", s_m: "%#{s_marca}%")
end
#Search section #2
def self.search_fec_min(s_codigo, s_den_cont, s_marca, s_fec_min)
where("codigo ilike :s_c and den_cont ilike :s_d and marca ilike :s_m and date_expired >= :s_fmin", s_c: "%#{s_codigo}%", s_d: "%#{s_den_cont}%", s_m: "%#{s_marca}%", s_fmin: "#{s_fec_min}")
end
index
<%= text_field_tag :s_codigo, params[:s_codigo], placeholder: "Search for cod" %>
<%= text_field_tag :s_den_cont, params[:s_den_cont], placeholder: "Search for DenominaciĆ³n" %>
<%= text_field_tag :s_marca, params[:s_marca], placeholder: "Search brand" %>
<%= date_select :s_fec_min, params[:s_fec_min], placeholder: "Search for date", :include_blank => true %>
Controller
if self.is_date(params[:s_fec_min])
#items = View_item.all.order("date_expired ASC").page(params[:page]).per(15).search_fec_min(params[:s_codigo], params[:s_den_cont], params[:s_marca], params[:s_fec_min])
elsif (params[:s_codigo] != "" or params[:s_den_cont] != "" or params[:s_marca] != "")
#items = View_item.all.order("date_expired ASC").page(params[:page]).per(15).search(params[:s_codigo], params[:s_den_cont], params[:s_marca])
else
#items = View_item.all.order("date_expired ASC").page(params[:page]).per(15)
end
MAX_URI_LENGTH is set to only 2083 characters for webrick server. On accessing url of length more than this limit throws WEBrick::HTTPStatus::RequestURITooLarge exception.
Try to switch to different server :
#Gemfile
gem 'thin'
$bundle install
$ rails s
=> Booting Thin
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop

NoMethodError in Human_resources/leaves#index

It was working few days ago, don't know what had went wrong...
**undefined method `name' for nil:NilClass**
Extracted source (around line #26):
23: %td= number_with_precision(employee.compensation_leave_balance, precision:1)
24: #calendar.tab-pane.fade
25: = calendar(:year => 2012, :month => 6, :first_day_of_week => 1, summary: "Leave Calendar", calendar_title: "June", month_header: true) do |date|
26: - render_leave_calendar_cell(date)
27: #trash.tab-pane.fade
28: = render 'table', leaves: #leaves.where(deleted: true)
app/helpers/leaves_helper.rb:11:in `block in events_for'
app/helpers/leaves_helper.rb:10:in `events_for'
app/helpers/leaves_helper.rb:4:in `render_leave_calendar_cell'
app/views/human_resources/leaves/index.html.haml:26:in `block in _app_views_human_resources_leaves_index_html_haml__145883348_88978910'
app/helpers/calendar_helper.rb:146:in `call'
app/helpers/calendar_helper.rb:146:in `block in calendar'
app/helpers/calendar_helper.rb:145:in `upto'
app/helpers/calendar_helper.rb:145:in `calendar'
app/views/human_resources/leaves/index.html.haml:25:in `_app_views_human_resources_leaves_index_html_haml__145883348_88978910'
really don't know what went wrong
a/h/leaves_helper.rb
1 module LeavesHelper
2 def render_leave_calendar_cell(date)
3 html = content_tag(:span, date.day, class: 'dayDisplay')
4 html += content_tag(:div, events_for(date))
5 raw(html)
6 end
7
8 def events_for(date)
9 html = ""
10 current_company.leaves.where("start_date <= '#{date}' and return_date > '#{date}'").where(deleted: false).each do |leave|
11 html += content_tag(:div, leave.applicant.name, class: 'leaveName')
12 end
13 raw html
14 end
could it be the date nil? how to fix this ><
much appreciate
Billy
as abhas already stated, leave.applicant is nil for at least one of the leaves.
go to your database and find out which it is. then figure out what to do with your leaves. delete them too, re-add the missing applicant or what ever data migration might be sensible.
a quick fix would be to skip if an applicant is missing:
html += content_tag(:div, leave.applicant.name, class: 'leaveName') if leave.applicant.present?
i would also have a look if you properly configured the delete cascades in your application. this often causes such problems. if you want to enforce safety in this regard, you should add database constraints, that ensure that no referenced entity gets deleted.

Strange behavior with acts_as_taggable_on's tagged_with method

Im trying to find all records that have similar tags to the currently viewed record.
My controller has:
def show
#tattoo =Tattoo.find(params[:id])
tags = #tattoo.style_list.join(", ")
#tattoos = Tattoo.tagged_with(tags, :any => true).limit(6)
end
(bonus points if anyone can tell me how to randomize the order of records in the arrary)
My view just loops through the array.
Anyway, it works almost all the time but I noticed it breaks occasionally and while troubleshooting I found that it breaks when I use tagged_with("jesse smith", :any => true) but it works when I try tagged_with("jason stephan", :any => true) or tagged_with("black ink", :any => true)
So each term has a space in it but for whatever reason 'jesse smith' kills the action.
My console shows that I have a routing error too:
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"tattoos", :member_id=>nil, :id=>#<Tattoo id: 170, description: "", status: "approved", member_id: nil, created_at: "2011-10-25 23:08:17", updated_at: "2011-11-17 16:56:55", file_file_name: "starry-eyed-rabid-squirrelweb.jpg", file_content_type: "image/jpeg", file_file_size: 294782, file_updated_at: "2011-10-25 23:08:17", album_id: nil, position: 116, favorite_count: 0, share_count: 1, file_remote_url: "http://www.jessesmithtattoos.com/wp-content/gallery...">}):
22: <ol class="small_tattoos">
23: <% #tattoos.each do |t| %>
24: <li>
25: <%= link_to image_tag(t.file.url(:tiny),:alt=>"#{t.style_list}, rtattoos, tattoos"), member_tattoo_path(t.member, t) %>
26: </li>
27: <% end %>
28: </ol>
app/views/index/show.html.erb:25:in `block (2 levels) in _app_views_index_show_html_erb___1839804211534816245_69842632179360__4333294961394575926'
app/views/index/show.html.erb:23:in `block in _app_views_index_show_html_erb___1839804211534816245_69842632179360__4333294961394575926'
app/views/index/show.html.erb:11:in `_app_views_index_show_html_erb___1839804211534816245_69842632179360__4333294961394575926'
So why does the one term cause a routing error and not the others?
I guess you have problem with path helper:
member_tattoo_path(t.member, t)
I see in your error description that
:member_id=>nil
So it turns out that tattoo tagged with jesse smith hasn't corresponding association with name 'member', and path helper, which need valid id, throws exception.

Resources