ruby
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| ruby [2026/03/14 10:17] – reddy | ruby [2026/03/15 19:56] (current) – reddy | ||
|---|---|---|---|
| Line 49: | Line 49: | ||
| rails g scaffold City name:string country: | rails g scaffold City name:string country: | ||
| </ | </ | ||
| + | |||
| + | ==== Multiple References ==== | ||
| + | |||
| + | To create multiple references to another model (for different attribute fields): | ||
| + | |||
| + | < | ||
| + | # The other model | ||
| + | rails g Country name | ||
| + | |||
| + | # In the scaffold command | ||
| + | rails g scaffold Staff residing_country: | ||
| + | |||
| + | # In the migration | ||
| + | t.references : | ||
| + | |||
| + | # In the model | ||
| + | belongs_to : | ||
| + | </ | ||
| + | |||
| + | ==== Resetting the Database ==== | ||
| + | |||
| + | < | ||
| + | rm storage/ | ||
| + | rails db:drop db:create db:migrate | ||
| + | </ | ||
| + | |||
| + | ==== Turbo Frames ==== | ||
| + | |||
| + | Turbo frames are for partial view updates. When the view is being rendered, return content within the turbo frame tag with the same identifier. domid(model_object) can be used to generate an identifier. | ||
| + | |||
| + | < | ||
| + | # In home/index view | ||
| + | <%= turbo_frame_tag " | ||
| + | This is a thing | ||
| + | <%= link_to ' | ||
| + | <% end %> | ||
| + | |||
| + | # In home/info view | ||
| + | <%= turbo_frame_tag " | ||
| + | This is another thing | ||
| + | <%= link_to ' | ||
| + | <% end %> | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Turbo Streams ==== | ||
| + | |||
| + | < | ||
| + | # In the view | ||
| + | <%= turbo_stream_from " | ||
| + | <div id=" | ||
| + | |||
| + | # In a controller | ||
| + | Turbo:: | ||
| + | ' | ||
| + | target: ' | ||
| + | content: DateTime.now | ||
| + | ) | ||
| + | </ | ||
| + | |||
ruby.1773479874.txt.gz · Last modified: by reddy
