Last active
December 25, 2015 03:29
-
-
Save mrded/6910228 to your computer and use it in GitHub Desktop.
Rails snippet
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
# rails generate controller Codes index show new create edit update destroy | |
class CodesController < ApplicationController | |
def index | |
@codes = Code.all | |
end | |
def show | |
@code = Code.find params[:id] | |
end | |
def new | |
@code = Code.new | |
end | |
def create | |
@code = Code.create! params[:code] | |
flash[:notice] = "#{@code.code} was successfully created." | |
redirect_to code_path(@code) | |
end | |
def edit | |
@code = Code.find params[:id] | |
end | |
def update | |
@code = Code.find params[:id] | |
if @code.update_attributes(params[:code]) | |
flash[:notice] = "#{@code.code} was successfully updated." | |
redirect_to code_path(@code) | |
else | |
render(action: 'edit') | |
end | |
end | |
def destroy | |
@code = Code.find params[:id] | |
@code.destroy | |
flash[:notice] = "#{@code.code} deleted." | |
redirect_to code_path | |
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
puts '-> CODES:' | |
codes = [ | |
{code: 'X99.7', description: 'Not known'}, | |
{code: 'X99.8', description: 'Outpatient procedure carried out but no appropriate OPCS-4 code available'}, | |
{code: 'X99.9', description: 'No outpatient procedure carried out'}, | |
] | |
Code.create(codes).each do | code | | |
puts 'Code: ' << code[:code] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment