Activity
Posted in User Onboarding Progress Bar Discussion
Great Chris, love this common features series :)
Posted in Rails Application Templates Discussion
I had to define the source paths
def source_paths
[File.expand_path(File.dirname(__FILE__))]
end
Posted in Rails Application Templates Discussion
I'm trying to create my own template using jumpstart as a guide but the command "directory" is not copying the files from my source directory.
I'm working in local in a folder called templates that contains the file template.rb
and also a subfolder with config/initializers/better_errors.rb
I'm doing as in jumpstart:
def copy_initializers
directory "config/initializers", force: true
end
But the file better_errors.rb
is not being copied in the Rails folder. The console log that I get is as follows:
exist config/initializers
identical config/initializers/application_controller_renderer.rb
identical config/initializers/assets.rb
identical config/initializers/backtrace_silencers.rb
identical config/initializers/cookies_serializer.rb
create config/initializers/cors.rb
identical config/initializers/filter_parameter_logging.rb
identical config/initializers/inflections.rb
identical config/initializers/mime_types.rb
create config/initializers/new_framework_defaults_5_1.rb
identical config/initializers/wrap_parameters.rb
I found this gem a couple of months ago and I don't see myself going back to kaminari, really good work!
EDIT. In this issue they talk about it, tried what the last comment says, still no luck.
https://github.com/basecamp/local_time/pull/53
locales/en.yml
but I get this syntax error:EDIT. Checking with YAMLLint, looks like the spaces between : and [ are not allowed.
I18n::InvalidLocaleData at /orderscan not load translations from /vagrant/src/pascual-apps/config/locales/en.yml: #<Psych::SyntaxError: (/vagrant/src/pascual-apps/config/locales/en.yml): did not find expected ',' or ']' while parsing a flow sequence at line 34 column 17>
Line 34 is the one for dayNames:
en:
date:
dayNames: [
"Sunday"
"Monday"
"Tuesday"
"Wednesday"
"Thursday"
"Friday"
"Saturday"
]
abbrDayNames: [
"Sun"
"Mon"
"Tue"
"Wed"
"Thu"
"Fri"
"Sat"
]
...
They point to this i18n.coffee file in their docs which contains the default english translations:
https://github.com/basecamp/local_time/blob/master/lib/assets/javascripts/src/local-time/config/i18n.coffee
LocalTime.config.i18n["es"] = { date: { dayNames: [ "Domingo", "Lunes", "Martes", "MiƩrcoles", "Jueves", "Viernes", "Sabado" ], abbrDayNames: ["Dom", "Lun", "Mar", "Mie", "Ju", "Vie", "Sab"], . . .
then in the same file i placed `LocalTime.config.locale = "es";`
-----------
Hi,
I want to use this gem, which was part of an old episode, but I need to translate the string literals to spanish in order to use it in my application.
The answer must be pretty obvious but I can't find it :(, any help would be appreciated.
Any ideas about what can be happening? I would appreciate any help.
class PartMaster < ApplicationRecord include PgSearch has_many :part_variants, foreign_key: 'sap_cod', primary_key: 'sap_cod' has_many :locations, foreign_key: 'sap_cod', primary_key: 'sap_cod' scope :con_stock, -> { where("stock > 0") } scope :planta, -> (planta) { where planta_cod: planta} pg_search_scope :search_keywords, against: {sap_cod: :A, descripcion_maestro: :B, fabricante: :C, ref_fabricante: :D}, ignoring: :accents, :associated_against => { part_variants: [:fabricante_prov, :ref_prov] }, using: { tsearch: {dictionary: 'spanish'}, trigram: {dictionary: "english"} } def self.search(params) recordset = PartMaster.joins(:part_variants).all recordset = recordset.con_stock if params[:stock].present? recordset = recordset.planta(params[:planta]) if params[:planta].present? recordset = recordset.search_keywords(params[:search]) recordset end end
I have been building an app these days. The functionality is nothing fancy at all, I have to connect to a client's SOAP webservice, fetch some data, save it into my pg database and build a search functionality based on this data.
The search has to be performed on two tables, both combined are like 80K rows. It needs to look for every word in the input text in several fields from these two tables, which have a classical assocation one to many.
Previous to get my hands dirty I was looking at the choices I had to get the functionality done (ransack, searchkick, scoped_search etc), but I ended up trying first just vanilla Active Record and I was very surprised to find that I could achieve the functionality way easier than I thought and with an acceptable response time, about to 400ms active record time for the most expensive queries in local.
So the problem is, the performance of this app in Heroku is way worse than in local (I'm developing using a vagrant box btw). On average, queries take 2-3 times longer than in local, so the user experience goes from acceptable to poor. I was wondering If someone could help to improve my query. I'm also worried about how the background job that fetchs the data is also way les performant than in local and about some issues with the memory, but that's a different story though.
The relevant snippets are these:
`part_master.rb` where the search method is implemented:
class PartMaster < ApplicationRecord has_many :part_variants, foreign_key: 'sap_cod', primary_key: 'sap_cod' has_many :locations, foreign_key: 'sap_cod', primary_key: 'sap_cod' scope :con_stock, -> { where("stock > 0") } scope :planta, -> (planta) { where planta_cod: planta} def self.search(params) recordset = PartMaster.joins(:part_variants).all recordset = recordset.con_stock if params[:stock].present? recordset = recordset.planta(params[:planta]) if params[:planta].present? recordset = search_keywords(params[:search], recordset) recordset end private def self.search_keywords(query, recordset) keywords = query.to_s.strip.split if query keywords.each do |keyword| recordset = recordset.where('part_masters.sap_cod ILIKE :q OR unaccent(descripcion_maestro) ILIKE unaccent(:q) OR fabricante ILIKE :q OR ref_fabricante ILIKE :q OR fabricante_prov ILIKE :q OR ref_prov ILIKE :q', q: "%#{keyword}%") end recordset.distinct.order(:sap_cod) end end end
And this is the call to the method from the controller:
def index parts = params[:search].present? ? PartMaster.search(params) : PartMaster.none @parts = parts.page(params[:page]).per(50) end
I have an index in every searchable field.
Thank you in advance!
Great episode Chris, newbie question here.
I adapted it to the app I'm currently working on, and works like a charm in localhost but in production (Heroku) the mark_as_read method gets only triggered after I do a hard refresh of the browser, otherwise the notifications remain as read: false even if I hit the link a hundred times. Might be an issue with turbolinks?
I read something in the slack channel about how the javascript should be running on turbolinks:load event instead of the dom content ready, but I'm not sure about how to do this. I could try just to remove turbolinks from the app but I would be losing a lot of speed. Any thoughts?