Skip to content

Instantly share code, notes, and snippets.

@maxmanders
Last active August 29, 2015 13:57
Show Gist options
  • Save maxmanders/9438829 to your computer and use it in GitHub Desktop.
Save maxmanders/9438829 to your computer and use it in GitHub Desktop.
rake routes | grep group
group_index GET /group(.:format) group#index
POST /group(.:format) group#create
new_group GET /group/new(.:format) group#new
edit_group GET /group/:id/edit(.:format) group#edit
group GET /group/:id(.:format) group#show
PATCH /group/:id(.:format) group#update
PUT /group/:id(.:format) group#update
DELETE /group/:id(.:format) group#destroy
2.0.0-p247 :003 > Group
=> Group(id: integer, name: string, created_at: datetime, updated_at: datetime)
Excerpt of routes.rb
...
resources :device do
resources :device_tags
end
resources :event do
resources :event_tags
end
resources :group
resources :production_state
root 'event#index'
...
<%= form_for @group do |f| %>
<% if @group.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@group.errors.count, "error") %> prohibited
this Group from being saved:</h2>
<ul>
<% @group.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :name %><br>
<%= f.text_field :name %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
~
class GroupController < ApplicationController
def index
@groups = Group.all
respond_to do |format|
format.html { render html: @groups }
format.json { render json: @groups.to_json }
end
end
def new
@group = Group.new
end
def show
@group = Group.find(params[:id])
end
def edit
@group = Group.find(params[:id])
end
end
<h1>Groups</h1>
<%= link_to 'New Group', new_group_path %>
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<% @groups.each do |group| %>
<tr>
<td><%= link_to group.name edit_group_path(group) %></td>
</tr>
<% end %>
</tbody
</table>
<h1>New Group</h1>
<%= render 'form' %>
<%= link_to 'Back', group_index_path %>
<h1>Show Group</h1>
<%= link_to 'Back', group_index_path %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment