Skip to content

Commit

Permalink
multiple destroy work with all orm
Browse files Browse the repository at this point in the history
  • Loading branch information
WaYdotNET committed Oct 5, 2012
1 parent 6005ef8 commit 8e21368
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
21 changes: 20 additions & 1 deletion padrino-admin/lib/padrino-admin/generators/orm.rb
Expand Up @@ -125,12 +125,31 @@ def update_attributes(params=nil)
end
end

def destroy
def destroy(params=nil)
case orm
when :ohm then "#{name_singular}.delete"
else "#{name_singular}.destroy"
end
end

def find_by_ids(params=nil)
case orm
when :datamapper, :couchrest then "#{klass_name}.all(id: #{params})"
when :mongoid then "#{klass_name}.find(#{params})"
else find(params)
end
end

def multiple_destroy(params=nil)
case orm
when :ohm then "#{params}.delete"
when :sequel then "#{klass_name}.destroy"
when :datamapper then "#{params}.destroy"
when :couchrest, :mongoid, :mongomapper then "#{params}.each(&:destroy)"
else "#{klass_name}.destroy #{params}"
end
end

end # Orm
end # Generators
end # Admin
Expand Down
Expand Up @@ -36,7 +36,8 @@ Admin.controllers :<%= @orm.name_plural %> do
end

put :update, :with => :id do
@<%= @orm.name_singular %> = <%= @orm.find("params[:id].to_s") %>
@<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %>
puts params[@<%= @orm.name_singular %>]

This comment has been minimized.

Copy link
@sumskyi

sumskyi Dec 19, 2012

Contributor

puts detected :/

This comment has been minimized.

Copy link
@WaYdotNET

WaYdotNET Dec 19, 2012

Author Contributor

thanks to check all my update.. you're crazy man :)

if @<%= @orm.name_singular %>
if <%= @orm.update_attributes("params[:#{@orm.name_singular}]") %>
flash[:notice] = '<%= @orm.klass_name %> was successfully updated.'
Expand Down Expand Up @@ -64,9 +65,12 @@ Admin.controllers :<%= @orm.name_plural %> do
end

delete :delete_multiple do
@<%= @orm.name_plural %> = <%= @orm.find("params[:#{@orm.name_singular}_ids]") %> if params[:<%= @orm.name_singular %>_ids]
halt 500 unless params[:<%= @orm.name_singular %>_ids]
if <%= @orm.klass_name %>.destroy @<%= @orm.name_plural %>
unless params[:<%= @orm.name_singular %>_ids]
flash[:error] = 'You must select at least one <%= @orm.name_singular %> '
redirect(url(:<%= @orm.name_plural %>, :index))
end
<%= @orm.name_plural %> = <%= @orm.find_by_ids(("params[:#{@orm.name_singular}_ids]")) %>
if <%= @orm.multiple_destroy(@orm.name_plural) %>
flash[:notice] = '<%= @orm.name_plural %> have been successfully destroyed.'
end
redirect url(:<%= @orm.name_plural %>, :index)
Expand Down

0 comments on commit 8e21368

Please sign in to comment.