Finding the available options for function calls?

I’m pretty new to Rails (8.0.1 at the moment), so please forgive a naive question.

What is the best way to get the details for a Rails function call?

For example, if I look up form.text_field in the API Docs I get this:

text_field(method, options = {})Link
Wraps ActionView::Helpers::FormHelper#text_field for form builders:

<%= form_with model: @user do |f| %>
  <%= f.text_field :name %>
<% end %>
Please refer to the documentation of the base helper for details.

Source: on GitHub

What I want to find is all the available options. I have run across :name and method: in example code, but it took me quite a while to stumble across placeholder: and class:.

I must be doing it wrong. What do others do?

Hi Bob.

Those are HTML options, not Rails per se. You can append them to any Rails view helper that generates an HTML tag by using Ruby hash syntax, e.g., placeholder: 'Enter name here', class: :some_css_class_name.

Regards, DJ

OK, can I use any HTML form and field attribute in the hash?

Nice! But where could I have found that in the Rails documentation?

In this case options are added as attributes - in others the options can be something else :slight_smile:

From the docs of text_field

Additional options on the input tag can be passed as a hash with options . These options will be tagged onto the HTML as an HTML element attribute as in the example shown.

Thanks! I see that now in the docs.

Part of learning Rails is also learning how to use it’s documentation!

From https://api.rubyonrails.org/v8.0/classes/ActionView/Helpers/FormHelper.html#method-i-text_field:

2 Likes