Reputation: 411
i would like to know if this is possible
ex:
in my Users controller
i have the edit and update method for the users#edit users/edit_acc view for update their pass and email
but i would like that the users create, edit and update their localization attributes like adress, city and etc on the same controller and view folder but with different view html
so this look like this users#edit_loc users/edit_loc
and as everytime that the user gonna create/update their attr, look like that just the update and edit methods are allowed for this.
thanks :)
Ex:
UserController
def edit
@user = User.find_by_auth_token!(cookies[:auth_token])
end
def update
@user = User.find_by_auth_token!(cookies[:auth_token])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { render action: "edit" }
flash[:success] = 'Conta Atualizada'
else
format.html { render action: "edit" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
def edit_loc
@user = User.find_by_auth_token!(cookies[:auth_token])
end
def update_loc
@user = User.find_by_auth_token!(cookies[:auth_token])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { render action: "edit_loc" }
flash[:success] = 'Conta Atualizada'
else
format.html { render action: "edit_loc" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
Upvotes: 0
Views: 542
Reputation: 3409
Just add the appropriate entries in config/routes.rb:
resources :users do
get :edit_loc
put :update_loc
end
Then create the view and add the actions to your controller.
Upvotes: 3