Skip to content

Instantly share code, notes, and snippets.

@lucasmarqs
Last active May 23, 2016 00:54
Show Gist options
  • Save lucasmarqs/252929871df1629e733332a044e32650 to your computer and use it in GitHub Desktop.
Save lucasmarqs/252929871df1629e733332a044e32650 to your computer and use it in GitHub Desktop.
Minimum CRUD on Rails
class Admin::ToolsController < AdminController
expose :tools, ancestor: :company
expose :tool, attributes: :tool_params
def create
if tool.save
set_flash_success_and_redirect_to admin_tools_path
else
render :new
end
end
def update
if tool.save
set_flash_success_and_redirect_to admin_tools_path
else
render :edit
end
end
def destroy
if tool.destroy
set_flash_success_and_redirect_to admin_tools_path
else
set_flash_error_and_redirect_to admin_tools_path
end
end
private
def tool_params
params.require(:tool).permit(:name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment