Skip to content

Instantly share code, notes, and snippets.

@tomfast tomfast/gist:476080
Created Jul 14, 2010

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.