Skip to content

Instantly share code, notes, and snippets.

@bmneely
Created April 12, 2014 18:01
Show Gist options
  • Save bmneely/10548520 to your computer and use it in GitHub Desktop.
Save bmneely/10548520 to your computer and use it in GitHub Desktop.
profiles_controller.rb
class ProfilesController < ApplicationController
def new
@user = User.find(params[:user_id])
@profile = Profile.new
end
def show
@user = User.find(params[:user_id])
@profile = Profile.find(params[:id])
end
def create
@user = User.find(params[:user_id])
@profile = Profile.new(params[:profile])
@profile.user = @user
if @profile.save
flash[:notice] = "Your Profile was saved!"
redirect_to [@user, @profile]
else
flash[:error] = "There was an error saving the profile. Please try again."
render :new
end
end
def edit
@user = User.find(params[:user_id])
@profile = Profile.find(params[:id])
end
def update
@user = User.find(params[:user_id])
@profile = Profile.find(params[:id])
if @profile.update_attributes(params[:profile])
flash[:notice] = "Profile was updated."
redirect_to [@user, @profile]
else
flash[:error] = "There was an error saving the Profile. Please try again."
render :edit
end
end
def home
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment