Created
May 29, 2011 12:48
-
-
Save haldun/997752 to your computer and use it in GitHub Desktop.
Controller template for decent exposure
This file contains hidden or 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
# mkdir -p lib/templates/rails/scaffold_controller/ | |
# Put this under lib/templates/rails/scaffold_controller/controller.rb | |
class <%= controller_class_name %>Controller < ApplicationController | |
respond_to :html, :json | |
<% unless options[:singleton] -%> | |
expose(:<%= table_name %>) { <%= orm_class.all(class_name) %> } | |
<% end -%> | |
expose(:<%= file_name %>) | |
<% unless options[:singleton] -%> | |
def index | |
respond_with <%= table_name %> | |
end | |
<% end -%> | |
def show | |
respond_with <%= file_name %> | |
end | |
def new | |
respond_with <%= file_name %> | |
end | |
def edit | |
respond_with <%= file_name %> | |
end | |
def create | |
if <%= file_name %>.save | |
flash.notice = '<%= class_name %> was created successfully.' | |
end | |
respond_with <%= file_name %> | |
end | |
def update | |
if <%= file_name %>.save | |
flash.notice = '<%= class_name %> was updated successfully.' | |
end | |
respond_with <%= file_name %> | |
end | |
def destroy | |
<%= file_name %>.destroy | |
respond_with <%= file_name %> | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment