@mirbook

Как это исправить — Rails показывает %2F вместо / в url?

gemfile
source 'https://rubygems.org'
ruby '2.3.3'

# core
gem 'rails', '4.2.0'
gem 'sass-rails'
gem 'sprockets'
gem 'compass-rails'
gem 'mongoid'
gem 'delayed_job_mongoid'
gem 'newrelic_rpm'
gem 'devise'
gem 'responders'
gem 'puma'

# front end & layouts
# gem 'bootstrap', '~> 4.0.0.alpha5'
# gem 'tether-rails'
gem 'bootstrap-sass'
gem 'turbolinks'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'therubyracer'
gem 'money-rails'
gem "font-awesome-rails"
gem 'nested_form'
gem 'haml'

gem 'dropzonejs-rails'
# gem 'twitter-bootstrap-rails'
gem 'sanitize'
gem 'russian'
gem 'ckeditor', github: 'galetahub/ckeditor'
gem 'chosen-rails'
# gem 'galetahub-simple_captcha', require: 'simple_captcha'
gem 'simple_captcha', :git => 'git://github.com/Azdaroth/simple-captcha.git', :branch => 'rails-4'
gem "letter_opener"

gem 'kaminari'
gem 'kaminari-i18n'
gem 'kaminari-mongoid'
gem 'bootstrap-kaminari-views'
gem 'toastr-rails'

# uploader
gem 'mini_magick'
gem 'unicode_utils'
gem 'carrierwave'
gem 'carrierwave-mongoid'

# serializers
gem 'bson_ext'

# elastic
gem 'tire'

gem 'rubyzip'

group :development do
  gem "spring"
  gem 'capistrano-rails', '~> 1.1.1'
  gem 'capistrano-rvm'
  gem 'capistrano-bundler', '~> 1.2'
  gem 'capistrano', '~> 3.7.1'

  # debug
  gem "better_errors"
  gem 'binding_of_caller'
end

group :test do
  gem 'test-unit'
end



group :development, :test do
  gem 'net-ssh', '~> 2.9.0'
  gem "airbrussh", :require => false
  gem 'pry-rails'
  gem 'quiet_assets'
end


Контроллер
products_controller
class ProductsController < ApplicationController

  respond_to :html

  def show
    load_product
    @suggestions = @product.category.products
    respond_with(@product)
  end
  
  private

  def load_product
    @product = Product.find_by(slug: params[:slug])
  end
end


Вьюха
%tr
  %td.color_bg
    = link_to product_path(product.slug) do
      = image_tag(product.picture_url(:mini))
  -# - color = "%06x" % (rand * 0xffffff)
  -# %td.color_bg{bgcolor: color}
  - @properties.each do |prop|
    %td
      = product.properties[prop[0]][1] if product.properties[prop[0]]
  -# %td.color_id= product.show_attribute(:color_id)
  -# %td.type=     product.show_attribute(:cover_type)
 
  -# %td.width=    product.show_attribute(:width, 'м')
  -# %td.length=   product.show_attribute(:length, 'м')
  -# %td.brend=    product.show_attribute(:vendor)
  %td.unit=     product.show_attribute(:unit)
  %td.price=    product.show_attribute(:price, 'р.')
  
  / TODO: link_to bye prodcut
  %td.bnt_buy
    %div{id: "product-#{product.id}"}
      = link_to add_item_to_cart_path(current_cart.id, product_id: product.id), method: 'PATCH', remote: true do
        %i.fa.fa-cart-plus{"aria-hidden" => "true"}


Routes.rb
Remexural::Application.routes.draw do
  mount Ckeditor::Engine => '/ckeditor'
  # devise_for :users

  root to: "index#index"

  post 'api/upload'
  get 'api/image_delete'

  resources :carts,    only: [:show]
  resources :news,     only: [:index, :show]

  # TODO: changes paths http://remexural.ru/produkty/uslugi
  resources :services, only: [:index, :show]

  # TODO: http://remexural.ru/produkty/orgsteklo-akrilovoe-steklo
  resources :groups, only: [:index] do
    collection do
      get ':slug', to: 'groups#show'#, as: 'show'
    end
  end


  get 'produkty/(*slug)', to: 'groups#show', as: 'show_groups'
  

  resources :categories, only: [:show], param: :slug
  resources :products,   only: [:show], param: :slug
  resources :knowledges, only: [:show, :index]
  resources :pages,      only: [:show] do
    collection do
      get ':slug', to: 'pages#show', as: 'show'
    end
  end


Пример url:
/samokleyaschiesya-plenki%2Fplenki-dlya-svetovoy-reklamy%2Fplenka-oracal-8500-7-let%2Fplenka-oracal-8500-7-let-126-50-528-serosinyaya

Почему %2F вместо / и как это поменять.
  • Вопрос задан
  • 178 просмотров
Решения вопроса 1
@mirbook Автор вопроса
Изменение маршрута на get дало нужный мне результат:
get 'produkty/(*slug)', to: 'groups#show', as: 'show_groups'
  get 'products/(*slug)', to: 'products#show', as: 'product'

  resources :categories, only: [:show], param: :slug
  #resources :products,   only: [:show], param: :slug
  resources :knowledges, only: [:show, :index]
  resources :pages,      only: [:show] do
    collection do
      get ':slug', to: 'pages#show', as: 'show'
    end
  end
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы