Skip to content

Instantly share code, notes, and snippets.

@limjinsun
Created November 21, 2019 19:18
Show Gist options
  • Select an option

  • Save limjinsun/96edf05a74c94e8f0e7b56c41e1dae9d to your computer and use it in GitHub Desktop.

Select an option

Save limjinsun/96edf05a74c94e8f0e7b56c41e1dae9d to your computer and use it in GitHub Desktop.
루비온레일즈 폼오토제너레이션 액티브레코드와 연동
<%= form_with(model: school, local: true) do |form| %>
<% if school.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(school.errors.count, "error") %> prohibited this school from being saved:</h2>
<ul>
<% school.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<% for attribute in school.attributes.keys %>
<div class="field">
<%= form.label attribute.humanize.downcase %>
<%= form.text_field attribute.humanize.downcase, :value => school.attributes[attribute].to_s %>
</div>
<% end %>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
<p id="notice"><%= notice %></p>
<% @schools.each do |school| %>
<table>
<thead>
<tr>
<td>key</td>
<td>value</td>
</tr>
</thead>
<tbody>
<% for attribute in school.attributes.keys %>
<tr>
<td><%= attribute.humanize %> </td>
<td><%= school.attributes[attribute].to_s %></td>
</tr>
<% end %>
<tr>
<td>
<b><%= link_to 'Show', school %></b>
<b><%= link_to 'Edit', edit_school_path(school) %></b>
<b><%= link_to 'Destroy', school, method: :delete, data: { confirm: 'Are you sure?' } %></b>
</td>
</tr>
</tbody>
</table>
<hr>
<hr>
<hr>
<% end %>
<h1 class="title"><%= link_to 'New School', new_school_path %></h1>
<p id="notice"><%= notice %></p>
<table>
<thead>
<tr>
<td>key</td>
<td>value</td>
</tr>
</thead>
<tbody>
<% for attribute in @school.attributes.keys %>
<tr>
<td><%= attribute.humanize %></td>
<td><%= @school.attributes[attribute].to_s %></td>
</tr>
<% end %>
<tr>
<td>
<%= link_to 'Edit', edit_school_path(@school) %> |
<%= link_to 'Back', schools_path %>
</td>
</tr>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment