Notes posted by chiperific

RSS feed
June 25, 2021 - (>= v5.2.3)
0 thanks

Moved from ActiveRecord to ActiveModel

Don’t let the depreciation warning scare you, Dirty lives under ActiveModel as of 3.0.0

apidock.com/rails/ActiveModel

April 5, 2021 - (v3.0.0 - v6.1.3.1)
0 thanks

Returns a string used for submit button label

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 searches for a key specific to the given object:

en:
  helpers:
    submit:
      post:
        create: "Add %{model}"
April 5, 2021 - (v6.0.0 - v6.1.3.1)
0 thanks

Access just the label text

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)