【问题标题】:URL is getting appended again in URL on clicking any link Rails在单击任何链接 Rails 时,URL 会再次附加到 URL 中
【发布时间】:2017-10-06 07:40:06
【问题描述】:

当我单击任何链接或使用重定向时,它总是在 URL 中附加 URL。就像在单击我的 URL 之前看起来像 http://plushcash-chat.backtrak.co/ 但是当我点击此处可见的 URL 变为:http://plushcash-chat.backtrak.co%2C%20plushcash-chat.backtrak.co/

我的路线看起来像:

root 'chatrooms#index'
  resources :chatrooms do
    collection do
      get :check_username
    end
  end

  resources :messages
  get '/signed_out', to: 'welcome#sign_out_user'
  get "leaderboards/top_affiliates"
  get '/chat', to: 'welcome#chat'
  mount ActionCable.server => '/cable'

控制器代码: 注册控制器

build_resource(configure_sign_up_params)

    resource.save
    yield resource if block_given?
    if resource.persisted?
      if resource.active_for_authentication?
        set_flash_message! :notice, :signed_up
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
        set_flash_message! :alert, :"signed_up_but_#{resource.inactive_message}"
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      respond_with resource
    end
    cookies.signed[:user_id] = current_user.id

它发生在所有控制器中。我正在使用:

if current_user.present?
      @chatroom = Chatroom.new(chatroom_params)
      if @chatroom.save
        respond_to do |format|
          format.html { redirect_to @chatroom }
          format.js
        end
      else
        respond_to do |format|
          flash[:notice] = {error: ["a chatroom with this topic already exists"]}
          format.html { redirect_to new_chatroom_path }
          format.js { render template: 'chatrooms/chatroom_error.js.erb'} 
        end
      end
    else
      redirect_to root_url
    end

【问题讨论】:

  • 粘贴控制器代码
  • 和视图,特别是表单。路线看起来不错。当我提交表单时,它重定向到那个错误的 url,但是当我再次点击主页时,我的会话继续。
  • puneet18 我在编辑后将上面的控制器代码粘贴到了我的问题中。
  • 所有这些代码都无关紧要。我们需要查看代码(带有链接的代码)。

标签: ruby-on-rails ruby routes url-redirection


【解决方案1】:

无论您在视图中做什么 - 在某处都有一个“,”。

您可以在浏览器控制台中自行检查:

> decodeURIComponent("%2C%20")
> ", "

只需检查您视图中设置链接的确切部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多