Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 更改网页中的URL_Ruby_Ruby On Rails 3_Url_Routes - Fatal编程技术网

Ruby 更改网页中的URL

Ruby 更改网页中的URL,ruby,ruby-on-rails-3,url,routes,Ruby,Ruby On Rails 3,Url,Routes,在同一页面中从一个选项卡移动到另一个选项卡时,如何更改URL地址?我想在何处更改routes.rb或controller中的代码 routes.rb: Rails.application.routes.draw do resources :dashboard, only: [:index] resources :profile do collection do patch 'update_profile' patch 'change_password'

在同一页面中从一个选项卡移动到另一个选项卡时,如何更改URL地址?我想在何处更改routes.rb或controller中的代码

routes.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
,现在当我选择“更新配置文件”选项卡时,我需要url是
localhost:3000/profile/update\u 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
class ProfileController
单击选项卡时会发生什么(按请求)?显示控制器代码。我已经添加了控制器代码,请检查一下好吗@JagdeepSinghWhat is current behavior?单击当前页面中的选项卡时,我得到了相同的url地址。即两个选项卡的localhost:3000/profile。如果我更新密码更改,url将更改,但我希望在单击选项卡时更改url