Read files in directory on ruby on rails
I suggest you use Dir.entries(“target_dir”) Check the documentation here
I suggest you use Dir.entries(“target_dir”) Check the documentation here
Since MySQL indexes are already case-insensitive, I’m guessing you’re dealing with PostgreSQL, which creates case-sensitive indexes by default. I’m answering here based on Rails 3.2.3 and PostgreSQL 8.4. It seems functional indexes are one more example of things that ActiveRecord can’t generate. Foreign keys and UUID columns are two more that come to mind. So … Read more
Rails has a convenience method for calculating the beginning of the week. irb(main):001:0> Date.today.beginning_of_week(:sunday) #=> Sun, 16 Dec 2012 See the Date Rails extensions for other possibilities: http://api.rubyonrails.org/classes/Date.html Update: Rails 5.2 adds convenience methods to find the next/previous occurrence of a day. [1] pry(main)> Date.today.prev_occurring(:sunday) #=> Sun, 29 Apr 2018 See the DateAndTime::Calculations documentation for … Read more
As of Rails 4.1.0, there’s now a better solution than the 4 year-old answers to this question: add the following line to your config file: config.action_view.raise_on_missing_translations = true I like to set this in the test environment only, but you might also want to set it in development. I would strongly advise against setting it … Read more
There’s now a method disable_ddl_transaction! that allows this, e.g.: class AddIndexesToTablesBasedOnUsage < ActiveRecord::Migration disable_ddl_transaction! def up execute %{ CREATE INDEX CONCURRENTLY index_reservations_subscription_id ON reservations (subscription_id); } end def down execute %{DROP INDEX index_reservations_subscription_id} end end
Rails 2 If you are still on rails 2 you will need to use: Client.select(‘distinct(name)’) Rails 3 If you are on Rails 3 you will need to use: Client.select(:name).uniq If you look at the equivalent section of the rails 3 guide you can see the difference between the two versions. Rails 4+ The .distinct option … Read more
gem looks for a configuration file .gemrc in your home directory, although you can specify another file on the command-line if you wish (with the –config-file modifier). There are three things you can specify in the configuration file: command-line arguments to be used every time gem runs command-line options for ’’RDoc’’ (used when generating documentation) … Read more
Try specifying the model and url separately: form_with(model: @activity, url: [@trip, @activity]) According the docs the the values for url are “Akin to values passed to url_for or link_to” so using an array should work. This also works with shallow nesting since the array is compacted.
The active_storage_blobs table does not exist yet. You need to first run: rails active_storage:install This command will add 2 migrations for 2 tables: active_storage_attachments and active_storage_blobs. These new migrations need to be run before the migrations you have above. There is a trick for this, you can consider manually changing the timestamp in the filenames … Read more
With save! validations always run. If any of them fail ActiveRecord::RecordInvalid gets raised. Try .save(validate: false)