Moved from ActiveRecord to ActiveModel (ActiveRecord::Dirty)
APIdock - Notes posted to Ruby on Rails
by
3y ago
Don’t let the depreciation warning scare you, Dirty lives under ActiveModel as of 3.0.0 apidock.com/rails/ActiveModel ..read more
Visit website
Returns a string used for submit button label (ActionView::Helpers::FormBuilder#submit_default_value)
APIdock - Notes posted to Ruby on Rails
by
3y ago
This private method returns the label used for the `f.submit` helper. apidock.com/rails/v5.2.3/ActionView/Helpers/FormBuilder/submit <%= form_for @post do |f| %> <%= f.submit %> <% end %> In the example above, if @post is a new record, this method returns “Create Post” as submit button label; otherwise, it uses “Update Post”. This method also checks for custom language using I18n under the helpers.submit key and using %{model} for translation interpolation: en: helpers: submit: create: "Create a %{model}" update: "Confirm changes to %{model}" It also s ..read more
Visit website
Access just the label text (ActionView::Helpers::FormBuilder#submit)
APIdock - Notes posted to Ruby on Rails
by
3y ago
One of the handiest features of `f.submit` is the auto-generated label text. Some styling frameworks don’t lend themselves to using `f.submit` without lots of tweaking. If you’re not using `f.submit` but still want to access the label text, note that there is a private method: f.send(:submit_default_value) One example (in Haml, using MaterializeCss): .row .col.s6.center %button{ type: 'submit', name: 'commit', data: { disable: { with: 'Submitting...' } }, class: 'waves-effect waves-light btn maroon' } = f.send(:submit_default_value ..read more
Visit website
Text improvement (ActiveRecord::Calculations#pluck)
APIdock - Notes posted to Ruby on Rails
by
3y ago
The statement about not loading a bunch of records is correct because pluck returns an Array of values, not a ActiveRecord::Relation or an Array of Records. The exact wording though may be: “…without retrieving from the database unused columns or loading a bunch of records just to grab the attributes you want ..read more
Visit website
Mr. (ActionMailer::Part#new)
APIdock - Notes posted to Ruby on Rails
by
3y ago
555 ..read more
Visit website
Mr. (ActionMailer::Part#new)
APIdock - Notes posted to Ruby on Rails
by
3y ago
555 ..read more
Visit website
Works even on nested structures (Hash#deep_symbolize_keys)
APIdock - Notes posted to Ruby on Rails
by
4y ago
@EdvardM added a note years ago saying this does not symbolize the keys of deeply nested hashes, which may have been the case for whatever version of ruby was available at the time, but in 4+, it definitely does work as described: hash = {"a" => :a, "b" => {z: [[{"c" => 3}, {"c" => 4}], []]}} hash.deep_symbolize_keys => {:a=>:a, :b=>{:z=>[[{:c=>3}, {:c=>4 ..read more
Visit website
Expect_any_instance_of(ActiveRecord::Relation).to receive(:create_with) and others do not work (ActiveRecord::Relation)
APIdock - Notes posted to Ruby on Rails
by
5y ago
If you’re doing expect_any_instance_of(ActiveRecord::Relation).to receive(:create_with) and it does not work, try: expect_any_instance_of(ActiveRecord::Associations::CollectionProxy).to receive(:create_with) { |proxy, attributes| expect(proxy.klass).to eq(RecordClass) expect(attributes[:....]).to eq(...) double('find_or_create_by!' => Proc.new {}) } or when testing “find_or_create_by” expect_any_instance_of(ActiveRecord::Associations::CollectionProxy).to receive(:find_or_create_by) { |proxy, attributes| expect(proxy.klass).to eq(RecordClass) expect(attributes[:....]).to eq ..read more
Visit website
To_sentence_exclusive (Array#to_sentence)
APIdock - Notes posted to Ruby on Rails
by
5y ago
By default, to_sentence combines elements inclusively by using ", and ". If you want to be exclusive and combine the elements using ", or ", you can either pass in lengthy options to to_sentence or use this handy extension I made to add to_sentence_exclusive to the Array class. class Array # Adds a simple method that overloads `to_sentence` except it uses "or" instead of "and", which is the default. # The reason for this is because `to_sentence` is extremely flexible but that results in a lot of code to get # the simple result of using "or" instead of "and". This makes it simple ..read more
Visit website
To_sentence_exclusive (Array#to_sentence)
APIdock - Notes posted to Ruby on Rails
by
5y ago
wtf ..read more
Visit website

Follow APIdock - Notes posted to Ruby on Rails on FeedSpot

Continue with Google
Continue with Apple
OR