person has_many :jokes joke belongs_to :person
Last active
August 29, 2015 14:08
-
-
Save maclover7/de95a5a14b1fd163437e to your computer and use it in GitHub Desktop.
Rails Sub-resources Routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for [:person, @joke] do |f| %> | |
<% if @joke.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@joke.errors.count, "error") %> prohibited this joke from being saved:</h2> | |
<ul> | |
<% @joke.errors.full_messages.each do |message| %> | |
<li><%= message %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class="field"> | |
<%= f.label :body %><br> | |
<%= f.text_area :body %> | |
</div> | |
<%= f.hidden_field :person_id %> | |
<div class="actions"> | |
<%= f.submit %> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Listing jokes</h1> | |
<table> | |
<thead> | |
<tr> | |
<th>Body</th> | |
<th colspan="3"></th> | |
</tr> | |
</thead> | |
<tbody> | |
<% @jokes.each do |joke| %> | |
<tr> | |
<td><%= joke.body %></td> | |
<!-- Errors begin here --> | |
<td><%= link_to 'Show', person_joke_path(joke) %></td> | |
<td><%= link_to 'Edit', edit_person_joke_path(joke) %></td> | |
<td><%= link_to 'Destroy', joke, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |
<!-- Errors end here --> | |
</tr> | |
<% end %> | |
</tbody> | |
</table> | |
<br> | |
<%= link_to 'New Joke', new_person_joke_path %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment