Created
January 19, 2010 02:48
-
-
Save anonymous/280611 to your computer and use it in GitHub Desktop.
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
# partial that's inserted into pages new and pages edit | |
<p> | |
<%= f.label :name %><br /> | |
<%= f.text_field :name %> | |
</p> | |
<p> | |
<%= f.label :admin? %><br /> | |
<%= f.check_box :admin %> | |
</p> | |
<p> | |
<%= f.label :parent_id %><br /> | |
<%= f.collection_select :parent_id, Page.find(:all), :id, :navlabel, :include_blank => true %> | |
</p> | |
<p> | |
<%= f.label :position %><br /> | |
<%= f.text_field :position, :size => '3' %> | |
</p> | |
<p> | |
<%= f.label :navlabel %><br /> | |
<%= f.text_field :navlabel %> | |
</p> | |
<p> | |
<%= f.label :layout %><br /> | |
<%= f.select :layout,layout_collect, {} %> | |
</p> |
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
# pages edit | |
<h1>Editing page</h1> | |
<% form_for(@object) do |f| %> | |
<%= f.error_messages %> | |
<%= render :partial => 'form', :locals => {:f => f} %> | |
<p> | |
<%= f.submit 'Update' %> | |
</p> | |
<% end %> | |
<%= link_to 'Back', pages_path %> |
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
class GlobalRestController < ApplicationController | |
def index | |
@objects = params[:controller].singularize.camelize.constantize.all | |
respond_to do |format| | |
format.html | |
format.xml { render :xml => @objects } | |
end | |
end | |
def show | |
@object = params[:controller].singularize.camelize.constantize.find(params[:id]) | |
respond_to do |format| | |
format.html | |
format.xml { render :xml => @object } | |
end | |
end | |
def new | |
@object = params[:controller].singularize.camelize.constantize.new | |
respond_to do |format| | |
format.html | |
format.xml { render :xml => @object } | |
end | |
end | |
def edit | |
@object = params[:controller].singularize.camelize.constantize.find(params[:id]) | |
end | |
def create | |
model = params[:controller].singularize.downcase | |
@object = params[:controller].singularize.camelize.constantize.new(params[model]) | |
respond_to do |format| | |
if @object.save | |
flash[:notice] = "#{params[:controller].singularize.camelize} was successfully created." | |
format.html { redirect_to(@object) } | |
format.xml { render :xml => @object, :status => :created, :location => @object } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @object.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
def update | |
model = params[:controller].singularize.downcase | |
@object = params[:controller].singularize.camelize.constantize.find(params[:id]) | |
respond_to do |format| | |
if @object.update_attributes(params[model]) | |
flash[:notice] = "#{params[:controller].singularize.camelize} was successfully updated." | |
format.html { redirect_to(@object) } | |
format.xml { head :ok } | |
else | |
format.html { render :action => "edit" } | |
format.xml { render :xml => @object.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
def destroy | |
@object = params[:controller].singularize.camelize.constantize.find(params[:id]) | |
@object.destroy | |
respond_to do |format| | |
format.html { redirect_to(@object) } | |
format.xml { head :ok } | |
end | |
end | |
end |
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
# if you have a controller called pages, you would substitute the instance variable @pages with @objects | |
<table> | |
<% @objects.each do |page| %> | |
<tr class="oddrow"> | |
<td class="leftAlign"><%=h page.name %></td> | |
<td class="leftAlign"><%=h page.navlabel %></td> | |
<td class="centerAlign"><%=h page.position %></td> | |
<td class="centerAlign"><%=h page.layout %></td> | |
<td class="centerAlign"><%=h page.admin? ? "Yes" : "No" %></td> | |
<td class="centerAlign"><%=h page.parent_id != nil ? "Yes" : "No" %></td> | |
<td class="centerAlign"><%= link_to "Show", :alt => "Show"), page %></td> | |
<td class="centerAlign"><%= link_to "Edit", :alt => "Edit"), edit_page_path(page) %></td> | |
<td class="centerAlign"><%= link_to "Destroy", :alt => "Destroy"), page, :confirm => 'Are you sure?', :method => :delete %></td> | |
</tr> | |
<% end %> | |
</table> |
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
# pages new | |
<h1>New page</h1> | |
<% form_for(@object) do |f| %> | |
<%= f.error_messages %> | |
<%= render :partial => 'form', :locals => {:f => f} %> | |
<p> | |
<%= f.submit 'Create' %> | |
</p> | |
<% end %> | |
<%= link_to 'Back', pages_path %> |
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
class PagesController < GlobalRestController | |
#nothing here needed unless you decide to overwrite a rest method | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment