I have a User model, which :has_many :widgets
Here is the ‘edit’ method:
def edit
@user = current_user
@user.widgets.build
end
I have an edit view which contains a user form and a widget form nested within it
In my UserController#update method, I save the data…all working as designed.
After save, I want to send the user to Widget#show with the ID of the widget that was just added to User.widgets
How do I get that ID?
Here is my update method:
def update
@user = User.find(params[:user][:id], :include => [:widgets])
if @user.update_attributes(params[:user])
redirect_to widget_path(????), notice: 'Your new Widget is ready' }
end
end
Couldn’t you scope the
@user.widgets.last.idrequest so that you are assured of getting their last widget, something like:@user.widgets.created_by(@user).last.id