Created
February 25, 2011 17:16
-
-
Save cookrn/844113 to your computer and use it in GitHub Desktop.
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
<!-- ## VIEW PARTIAL FILE _sub_menu.html.erb --> | |
<% content_for :sub_menu do %> | |
<ul id="sub_nav"> | |
<% # Default tab helper function always on for fancy_things sub-tab so <li> constructed manually below %> | |
<li class="<%= ( params[:action] == "index" ) ? "selected" : "" %>"><%= link_to t("fancy_things") , admin_fancy_things_path %></li> | |
<%= tab :new_fancy_thing , :route => :new_admin_fancy_thing , :match_path => '/fancy_things/new' , :css_class => 'last' %> | |
</ul> | |
<% end %> | |
<!-- ## VIEW PARTIAL FILE _form.html.erb --> | |
<%= f.field_container :name do %> | |
<%= f.label :name, t("name")%><br /> | |
<%= f.text_field :name %> | |
<% end %> | |
<%= f.field_container :description do %> | |
<%= f.label :description , t("description")%><br /> | |
<%= f.text_field :description %> | |
<% 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
## CONTROLLER FILE fancy_things_controller.rb | |
class Admin::FancyThingsController < Admin::BaseController | |
# we don't want a show method | |
resource_controller :except => [ :show ] | |
# redirect to the edit action after create | |
create.response do |wants| | |
wants.html { redirect_to edit_admin_fancy_thing_url( @fancy_thing ) } | |
end | |
# redirect to the edit action after update | |
update.response do |wants| | |
wants.html { redirect_to edit_admin_fancy_thing_url( @fancy_thing ) } | |
end | |
end | |
## ROUTES FILE routes.rb | |
Rails.application.routes.draw do | |
# ... | |
namespace :admin do | |
# ... | |
resources :fancy_things, :except => [ :show ] | |
# ... | |
end | |
# ... | |
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
## HOOKS FILE custom_spree_hooks.rb | |
class CustomSpreeHooks < Spree::ThemeSupport::HookListener | |
# add our navigation tab | |
insert_after :admin_tabs do | |
%( <%= tab :fancy_things %> ) | |
end | |
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
## FILE en.yml | |
en: | |
fancy_things: Fancy Things | |
fancy_thing: Fancy Thing | |
name: Name | |
description: Description | |
new_fancy_thing: New Fancy Thing | |
edit_fancy_thing: Edit Fancy Thing |
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
<!-- ## VIEW FILE index.html.erb --> | |
<%= render :partial => 'sub_menu' %> | |
<h1><%= t("fancy_things")%></h1> | |
<table class="index"> | |
<tr> | |
<%= hook :admin_fancy_thing_index_headers do %> | |
<th><%= t("name") %></th> | |
<th><%= t("description") %></th> | |
<% end %> | |
<th> | |
<%= hook :admin_fancy_thing_index_header_actions %> | |
</th> | |
</tr> | |
<% @fancy_things.each do |fancy_thing| %> | |
<tr id="<%= dom_id fancy_thing %>"> | |
<%- locals = { :fancy_thing => fancy_thing } %> | |
<%= hook :admin_fancy_thing_index_rows, locals do %> | |
<td><%= fancy_thing.name %></td> | |
<td><%= fancy_thing.description %></td> | |
<% end %> | |
<td class="actions"> | |
<%= hook :admin_fancy_thing_index_row_actions, locals do %> | |
<%= link_to_edit fancy_thing %> | |
| |
<%= link_to_delete fancy_thing %> | |
<% end %> | |
</td> | |
</tr> | |
<% end %> | |
</table> |
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
## MIGRATION FILE 20110209222632_create_fancy_things_table.rb | |
class CreateFancyThingsTable < ActiveRecord::Migration | |
def self.up | |
create_table :fancy_things do |t| | |
t.string :name | |
t.string :description | |
t.timestamps | |
end | |
end | |
def self.down | |
drop_table :fancy_things | |
end | |
end | |
## MODEL FILE fancy_thing.rb | |
class FancyThing < ActiveRecord::Base | |
validates_presence_of :name, :description | |
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
<!-- ## VIEW FILE new.html.erb --> | |
<%= render :partial => 'sub_menu' %> | |
<h1><%=t("new_fancy_thing")%></h1> | |
<%= render 'shared/error_messages', :target => @fancy_thing %> | |
<%= form_for(:fancy_thing, :url => admin_fancy_things_url) do |f| %> | |
<%= render :partial => "form", :locals => { :f => f } %> | |
<%= render :partial => "admin/shared/new_resource_links" %> | |
<% end %> | |
<!-- ## VIEW FILE edit.html.erb --> | |
<%= render :partial => 'sub_menu' %> | |
<h1><%=t("edit_fancy_thing")%></h1> | |
<%= render 'shared/error_messages', :target => @fancy_thing %> | |
<%= form_for(:fancy_thing, :url => object_url, :html => { :method => :put }) do |f| %> | |
<%= render :partial => "form", :locals => { :f => f } %> | |
<%= render :partial => "admin/shared/edit_resource_links" %> | |
<% end %> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment