Изменение URL на веб-странице - PullRequest
0 голосов
/ 14 мая 2018

Как я могу изменить URL-адрес при переходе с одной вкладки на другую на той же странице?Где я хочу изменить код либо в файле rout.rb, либо в контроллере?

rout.rb:

Rails.application.routes.draw do
  resources :dashboard, only: [:index]
  resources :profile do
    collection do
      patch 'update_profile'
      patch 'change_password'

    end
  end

  devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }

  root 'dashboard#index'
end

Мой текущий URL-адрес localhost:3000/profile, теперь, когда я выбираю вкладку update_profileмне нужно, чтобы URL был localhost:3000/profile/update_profile без рендеринга новой страницы

код контроллера:

class ProfileController < ApplicationController
  before_action :set_user, only: %i[index update_profile]

  def index

    @address = if @user.address
                 @user.address
               else
                 Address.new
               end
  end

  def update_profile
    respond_to do |format|
      if @user.update(user_params)
        format.html { redirect_to profile_index_path, notice: 'Profile was successfully updated.' }
      else
        format.html { render :index }
      end
    end
  end

  def change_password
   @user = current_user
    if @user.update_with_password(user_password_params)
      redirect_to root_path
    else
      render "index"
    end
 end

private

  def set_user
    @user = User.find(current_user.id)
  end

  def user_params
    params.require(:user).permit(:name)
  end

  def address_params
    params.require(:user).permit(address: %i[area state country])
  end

  def user_password_params
    params.require(:user).permit(:password, :password_confirmation, :current_password)
  end
end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...