Rails: Added new Action in Controller, but there is no path?
- by Newbie
Hello!
I try to do following:
A user is on his profile page. Now he edits his profile. He klicks on update and the data is saved.
Now I want to redirect the user to another kind of profile-edit-page.
I did the following in my users_controller.rb:
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
if(@user.team_id != nil)
format.html { redirect_to(@user) }
else
format.html { redirect_to choose_team_path }
end
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
def choose_team
@user = User.find(params[:id])
end
I created a view: /users/choose_team.html.erb
Now I get the following error:
undefined local variable or method `choose_team_path' for #<UsersController:0x1f56650>
So I added choose_team to my routes.rb:
map.choose_team 'choose-team', :controller => 'users', :action => 'choose_team'
Now, after submitting my first edit form, it redirects me to http://localhost:3000/choose-team
and I get following error: Couldn't find User without an ID
What I want:
If a user has no team_id, he should be redirected to my choose_team.html.erb for choosing a team, else he should be redirected to his profile/show.
How to do this?