class FastCrud::FastCrud
Public Instance Methods
create(location = nil)
click to toggle source
# File lib/fast_crud.rb, line 25 def create(location = nil) @resource = model.new(model_params) if @resource.save flash[:success] = "#{model} successfully created!" if location redirect_to location else redirect_to @resource end else flash[:danger] = "Error creating #{model}: #{@resource.errors.full_messages.join(' - ')}" render 'new' end end
destroy(location = nil)
click to toggle source
# File lib/fast_crud.rb, line 57 def destroy(location = nil) @resource = model.find(params[:id]) @resource.destroy if location redirect_to location else redirect_to eval("#{controller_name}_path") end end
edit()
click to toggle source
# File lib/fast_crud.rb, line 21 def edit @resource = model.find(params[:id]) end
index()
click to toggle source
# File lib/fast_crud.rb, line 5 def index if request.filtered_parameters.has_rkey? /_id/ @collection = nested_collection else @collection = model.all end end
new()
click to toggle source
# File lib/fast_crud.rb, line 17 def new @resource = model.new end
show()
click to toggle source
# File lib/fast_crud.rb, line 13 def show @resource = model.find(params[:id]) end
update(location = nil)
click to toggle source
# File lib/fast_crud.rb, line 41 def update(location = nil) @resource = model.find(params[:id]) if @resource.update(model_params) flash[:success] = "#{model} successfully updated!" if location redirect_to location else redirect_to @resource end else flash[:danger] = "Error updating #{model}: #{@resource.errors.full_messages.join(' - ')}" render 'edit' end end
Private Instance Methods
model()
click to toggle source
# File lib/fast_crud.rb, line 68 def model controller_name.classify.constantize end
nested_collection()
click to toggle source
# File lib/fast_crud.rb, line 72 def nested_collection path = request.fullpath.split("/").reject {|a| a.empty?}.last(3) path.first.classify.constantize.find(path[1]).send(path.last) end