Skip to content

Instantly share code, notes, and snippets.

@tomfast
Created July 14, 2010 21:14
Show Gist options
  • Save tomfast/476080 to your computer and use it in GitHub Desktop.
Save tomfast/476080 to your computer and use it in GitHub Desktop.
def new
@accessory = Accessory.new({ :client_id => params[:client_id] })
# b/c an accessory can be nested under client or lifting_device
@parent = find_parent
@users = (User.client_users @client.id).client_user_roles
end
def create
@parent = find_parent
@accessory = @parent.accessories.build(params[:accessory])
if @accessory.save
flash[:notice] = "Accessory created successfully."
if @parent.is_a? Client
redirect_to client_accessory_path(@parent, @accessory)
else
redirect_to lifting_device_accessory_path(@parent, @accessory)
end
else
@users = (User.client_users @client.id).client_user_roles
render 'new'
end
end
def show
@parent = find_parent
@accessory = @parent.accessories.find(params[:id])
end
@tomfast
Copy link
Author

tomfast commented Jul 14, 2010

Please see line#6, line#20.

We need to make sure the proper vars are set for the form if update / create attempt was not valid.

I'm wondering if this data should be retrieved in the view instead of the controller? I'm not a fan of the duplication of code right now.

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment