Skip to content

Instantly share code, notes, and snippets.

@ekumachidi
Created November 18, 2015 10:24
Show Gist options
  • Save ekumachidi/af5949fae670e7745503 to your computer and use it in GitHub Desktop.
Save ekumachidi/af5949fae670e7745503 to your computer and use it in GitHub Desktop.
def new
@user = User.new
@package = Package.all
end
def create
@user = user.new(user_params)
if @user.save
redirect_to :action => ‘list’
else
@packages = Packages.all
render :new
end
end
def user_params
params.require(:user).permit(:name, :phone, :package_id)
end
def list
@user = user.all
end
def show
@user = user.find(params[:id])
end
def update
@user = user.find(params[:id]) 
if @user.update_attributes(user_param)
redirect_to :action => ‘show’, :id => @user
else
render :edit #that is if u have an edit action/view
end
end
def edit
@user = user.find(params[:id])
end
def delete
user.find(params[:id]).destroy
redirect_to :action => ‘list’
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment