Created
April 12, 2014 18:01
-
-
Save bmneely/10548520 to your computer and use it in GitHub Desktop.
profiles_controller.rb
This file contains 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
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