Ruby rails: view helpers: Difference between revisions
From wikinotes
(→forms) |
(→forms) |
||
Line 48: | Line 48: | ||
== forms == | == forms == | ||
<blockquote> | |||
=== form types === | |||
<blockquote> | <blockquote> | ||
form for an action | form for an action | ||
Line 65: | Line 67: | ||
<% end %> | <% end %> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- form types --> | |||
=== button_tag === | === form fields === | ||
<blockquote> | |||
==== button_tag ==== | |||
<blockquote> | <blockquote> | ||
button with icon | button with icon | ||
Line 76: | Line 81: | ||
</blockquote><!-- button_tag --> | </blockquote><!-- button_tag --> | ||
=== select_tag === | ==== select_tag ==== | ||
<blockquote> | <blockquote> | ||
* select https://api.rubyonrails.org/files/actionview/lib/action_view/helpers/form_options_helper_rb.html | * select https://api.rubyonrails.org/files/actionview/lib/action_view/helpers/form_options_helper_rb.html | ||
Line 100: | Line 105: | ||
</blockquote><!-- select_tag --> | </blockquote><!-- select_tag --> | ||
=== submit_tag === | ==== submit_tag ==== | ||
<blockquote> | <blockquote> | ||
</blockquote><!-- submit_tag --> | </blockquote><!-- submit_tag --> | ||
</blockquote><!-- form fields --> | |||
</blockquote><!-- forms --> | </blockquote><!-- forms --> | ||
</blockquote><!-- common helpers --> | </blockquote><!-- common helpers --> |
Latest revision as of 18:55, 1 September 2021
Documentation
View Helpers https://api.rubyonrails.org/classes/ActionView/Helpers.html Specific Helpers formhelper https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html urlhelper
Common Helpers
Url Helpers
See ruby rails: url helpers for details.
a_rails_route_path(...) # rails_route/a a_rails_route_url(...) # https://domain.com/rails_route/aredirect_back
Redirect back to the page you came to this one from.
redirect_back( fallback_location: .., flash: { notice: "completed blah" } )Elements
link_to
button_to
button_to("Go Here", some_rails_path(123))forms
form types
form for an action
<%= form_tag(action: "post") do %> <%= select_tag("users", options_for_select(["Alex", "Courtney", "Sam"], selected: "Courtney")) %> <%= submit_tag %> <!-- ... --> <% end %>form for creating an ActiveRecord model (id:
"new_person"
)<%= form_for(@person) do %> <%= select_tag("friends", options_for_select(["Alex", "Courtney", "Sam"], selected: "Alex")) %> <!-- ... --> <% end %>form fields
button_tag
button with icon
<%= button_tag(type: "submit") do %> <i class=" icon-repeat"></i> <% end %>select_tag
- select https://api.rubyonrails.org/files/actionview/lib/action_view/helpers/form_options_helper_rb.html
- select_tag https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-select_tag
<!-- select with label/value --> <!-- params={"number"=>2} --> <%= select_tag("number", options_for_select({ "a" => 1, "b" => 2})) %><!-- select from collection --> <!-- params={"letter"=>"b"} --> <%= select_tag("letter", options_for_select(["a", "b", "c"], selected: "b")) %><!-- show "Alex", save 1 --> <!-- params={"user"=>{ "id"=> 2}} --> <% select("user", "id", [["alex", 1], ["courtney", 2], ["sam", 3]]) %>submit_tag