class Object
Public Class Methods
<(%=parent_singular_name%>_page(page))
click to toggle source
# File lib/generators/dust/albums/templates/app/models/photo.rb, line 21 def self.<%=parent_singular_name%>_page(page) roots.paginate(:per_page => 24, :page => page) end
page(search, page)
click to toggle source
# File lib/generators/dust/albums/templates/app/models/album.rb, line 11 def self.page(search, page) with_permissions_to(:manage).search(search).order("title").paginate(:per_page => 10, :page => page) end
search(search)
click to toggle source
# File lib/generators/dust/albums/templates/app/models/album.rb, line 19 def self.search(search) if search where("title LIKE ?", "%#{search}%") else scoped end end
view(page)
click to toggle source
# File lib/generators/dust/albums/templates/app/models/album.rb, line 15 def self.view(page) roots.paginate(:per_page => 10, :page => page) end
Public Instance Methods
array()
click to toggle source
# File lib/generators/dust/albums/templates/app/controllers/photos_controller.rb, line 69 def array menu_sort(params[:ul]) flash[:notice] = "Successfully Sorted <%=child_plural_class_name%>." end
coerce(params)
click to toggle source
# File lib/generators/dust/albums/templates/app/controllers/photos_controller.rb, line 75 def coerce(params) if params[:<%=child_singular_name%>].nil? h = Hash.new h[:<%=child_singular_name%>] = Hash.new h[:<%=child_singular_name%>][:<%=parent_singular_name%>_id] = params[:<%=parent_singular_name%>_id] h[:<%=child_singular_name%>][:title] = params[:title] h[:<%=child_singular_name%>][:file] = params[:Filedata] h[:<%=child_singular_name%>][:file].content_type = MIME::Types.type_for(h[:<%=child_singular_name%>][:file].original_filename).to_s h else params end end
create()
click to toggle source
# File lib/generators/dust/scaffold/templates/actions/create.rb, line 1 def create @<%= singular_name %> = ::App::<%= class_name %>.new(params[:app_<%= singular_name %>]) if @<%= singular_name %>.save flash[:notice] = "Successfully created <%= model_name.underscore.humanize.downcase %>." redirect_to <%= item_path('url') %> else render :action => 'new' end end
destroy()
click to toggle source
# File lib/generators/dust/albums/templates/app/controllers/photos_controller.rb, line 56 def destroy if request.post? if params[:<%=child_singular_name%>_ids] params[:<%=child_singular_name%>_ids].each do |<%=child_singular_name%>| @<%=child_singular_name%> = <%=child_class_name%>.find <%=child_singular_name%> @<%=child_singular_name%>.destroy end flash[:notice] = "<%=child_plural_class_name%> Successfully deleted!" end redirect_to(<%=parent_singular_name%>_path(@<%=child_singular_name%>.<%=parent_singular_name%>)) end end def array menu_sort(params[:ul]) flash[:notice] = "Successfully Sorted <%=child_plural_class_name%>." end private def coerce(params) if params[:<%=child_singular_name%>].nil? h = Hash.new h[:<%=child_singular_name%>] = Hash.new h[:<%=child_singular_name%>][:<%=parent_singular_name%>_id] = params[:<%=parent_singular_name%>_id] h[:<%=child_singular_name%>][:title] = params[:title] h[:<%=child_singular_name%>][:file] = params[:Filedata] h[:<%=child_singular_name%>][:file].content_type = MIME::Types.type_for(h[:<%=child_singular_name%>][:file].original_filename).to_s h else params end end end
edit()
click to toggle source
# File lib/generators/dust/albums/templates/app/controllers/photos_controller.rb, line 37 def edit if params[:edit] == '<%=child_singular_name%>' render :layout => false @<%=child_singular_name%> = <%=child_class_name%>.find(params[:id]) else @<%=child_singular_name%> = <%=child_class_name%>.find(params[:id]) end end def update @<%=child_singular_name%> = <%=child_class_name%>.find(params[:id]) if @<%=child_singular_name%>.update_attributes(params[:<%=child_singular_name%>]) flash[:notice] = "Successfully updated <%=child_singular_name%>." redirect_to <%=parent_singular_name%>_url(@<%=child_singular_name%>.<%=parent_singular_name%>) else render :action => 'edit' end end
index()
click to toggle source
# File lib/generators/dust/albums/templates/app/controllers/photos_controller.rb, line 8 def index @<%=child_plural_name%> = <%=child_class_name%>.page(params[:search], params[:page]) @<%=child_singular_name%>_<%=parent_plural_name%> = @<%=child_plural_name%>.group_by { |<%=child_singular_name%>| <%=child_singular_name%>.<%=parent_singular_name%>.title } end
new()
click to toggle source
# File lib/generators/dust/albums/templates/app/controllers/photos_controller.rb, line 19 def new @<%=child_singular_name%> = <%=child_class_name%>.new end def create newparams = coerce(params) @<%=child_singular_name%> = <%=child_class_name%>.new(newparams[:<%=child_singular_name%>]) if @<%=child_singular_name%>.save flash[:notice] = "Successfully created <%=child_singular_name%>." respond_to do |format| format.html { redirect_to @<%=child_singular_name%>.<%=parent_singular_name%> } format.json { render :json => { :result => 'success', :<%=child_singular_name%> => <%=child_singular_name%>_url(@<%=child_singular_name%>) } } end else render :action => 'new' end end
show()
click to toggle source
# File lib/generators/dust/albums/templates/app/controllers/photos_controller.rb, line 13 def show @<%=child_singular_name%> = <%=child_class_name%>.find(params[:id], :include => :<%=parent_singular_name%>) @total_uploads = <%=child_class_name%>.find(:all, :conditions => { :<%=parent_singular_name%>_id => @<%=child_singular_name%>.<%=parent_singular_name%>.id}) @<%=parent_singular_name%> = @<%=child_singular_name%>.<%=parent_singular_name%> end
test_create_invalid()
click to toggle source
# File lib/generators/dust/scaffold/templates/tests/testunit/actions/create.rb, line 1 def test_create_invalid <%= class_name %>.any_instance.stubs(:valid?).returns(false) post :create assert_template 'new' end def test_create_valid <%= class_name %>.any_instance.stubs(:valid?).returns(true) post :create assert_redirected_to <
test_destroy()
click to toggle source
# File lib/generators/dust/scaffold/templates/tests/testunit/actions/destroy.rb, line 1 def test_destroy <%= singular_name %> = <%= class_name %>.first delete :destroy, :id => <%= singular_name %> assert_redirected_to <%= items_path('url') %> assert !<%= class_name %>.exists?(<%= singular_name %>.id) end
test_edit()
click to toggle source
# File lib/generators/dust/scaffold/templates/tests/testunit/actions/edit.rb, line 1 def test_edit get :edit, :id => <
test_index()
click to toggle source
# File lib/generators/dust/scaffold/templates/tests/testunit/actions/index.rb, line 1 def test_index get :index assert_template 'index' end
test_new()
click to toggle source
# File lib/generators/dust/scaffold/templates/tests/testunit/actions/new.rb, line 1 def test_new get :new assert_template 'new' end
test_show()
click to toggle source
# File lib/generators/dust/scaffold/templates/tests/testunit/actions/show.rb, line 1 def test_show get :show, :id => <
test_update_invalid()
click to toggle source
# File lib/generators/dust/scaffold/templates/tests/testunit/actions/update.rb, line 1 def test_update_invalid <%= class_name %>.any_instance.stubs(:valid?).returns(false) put :update, :id => <%= class_name %>.first assert_template 'edit' end def test_update_valid <%= class_name %>.any_instance.stubs(:valid?).returns(true) put :update, :id => <%= class_name %>.first assert_redirected_to <%= item_path_for_test('url') %> end
update()
click to toggle source
# File lib/generators/dust/scaffold/templates/actions/update.rb, line 1 def update @<%= singular_name %> = ::App::<%= class_name %>.find(params[:id]) if @<%= singular_name %>.update_attributes(params[:app_<%= singular_name %>]) flash[:notice] = "Successfully updated <%= model_name.underscore.humanize.downcase %>." redirect_to <%= item_path('url') %> else render :action => 'edit' end