Change rails route to params in path - ruby-on-rails

Google bot wants to open my Ajax address like:
http://ots.wlasowy.ru/ru?_escaped_fragment_=/ru/pages/service
I have a record like match 'pages/service', :to => 'pages#service' in routes.rb.
What else I need to add to routes.rb?
My routes.rb:
scope "(:locale)", :locale => /en|ru/ do
match '/pages/news' => 'pages#news'
match '/articles/page/:page', :to => 'pages#news'
match '/pages/home' => 'pages#home'
resources :pages
resources :articles
resources :vacancies
mount Ckeditor::Engine => '/ckeditor'
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
devise_for :users
devise_scope :user do
get "sign_in", :to => "devise/sessions#new"
end
end

Add your route.rb, view files. You have some bugs in your code.

Related

Redirecting “/” to “/sub-directory” When Running Rails App as a Sub-Directory?

I am running my rails app as sub-directory (for apache mapping reasons):
config.ru:
map '/sub-directory' do
run Rails.application
end
application.rb:
config.root_directory = "/sub-directory/"
config.action_controller.relative_url_root = '/sub-directory'
so now my app (it's root) is ran from the route http://localhost:3000/sub-directory. The problem is when I go to http://localhost:3000/ I get the page:
Not Found: /
I understand I am getting that because my app isn't running in there anymore but I would like that route to redirect to http://localhost:3000/sub-directory. Is there anyway I can accomplish this?
if this helps, routes.rb:
require 'resque/server'
Rails.application.routes.draw do
get "handle/:handle" => "handles#index"
get "/tag/:hashtag" => "tags#index"
get "handles/:handle" => "handles#index"
get "/tags/:hashtag" => "tags#index"
devise_for :users, :controllers => {
:registrations => "registrations",
:passwords => "passwords"
}
devise_scope :user do
get "/email" => "registrations#email"
post "/registrations/check_email" => "registrations#check_email"
get "/users/sign_in" => "registrations#signup"
end
authenticated :user do
devise_scope :user do
root :to => redirect("app"), as: :authenticated_root
get "/app", :to => 'reports#index'
end
end
unauthenticated do
devise_scope :user do
root to: 'registrations#new'
end
end
get '/oauth' => 'social_platforms#new'
get "/auth/:provider/callback" => "social_platforms#create"
get '/login', :to => 'sessions#new', :as => :login
# match '/auth/failure' => 'sessions#failure', :via => [:get]
# get '/reports', to: 'pages#reports', as: :reports
resources :reports, only: [:show, :index]
get '/get_report', to: 'reports#get_report'
get '/check_token', to: 'reports#check_token'
mount Resque::Server.new, at: "/resque"
get '*path' => redirect('/')
end

how to use new_user_session route from devise as the root path?

Problem - I don't know how to set the new_user_session route from devise gem as the root path in Rails app.
Rails.application.routes.draw do
devise_for :users
resources :dashboard
root to: "home#index"
Place this line in routes.rb
devise_scope :user do
root :to => 'devise/sessions#new'
end
You need to set default session route.
Replace with .
devise_for :users, :controllers => {:registrations => "registrations", :sessions => "sessions"}
devise_for :users do
get '/users/sign_in', :to => 'devise/sessions#new', :as => :new_user_session
get '/users/sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
end
and root to
devise_scope :user do
get "/" => "sessions#new"
end

Rewriting Rails routes

Currently I am working on a blog engine in RoR and I encounter severa issues with routing.
The routes.rb looks like this:
match '/admin', :to => 'posts#new'
match '/get/:id', :to => 'posts#get'
match '/new', :to => 'posts#new'
delete '/:id', :to => 'posts#destroy'
post '/edit/:id', :to => 'posts#update'
put '/edit/:id', :to => 'posts#update'
get '/edit/:id', :to => 'posts#new', :as => 'post'
get '/:slug', :to => 'posts#show', :as => 'post'
root :to => 'posts#index'
and I would like to transform it in something like:
resources :admin do
resources :posts
end
Any help would be very appreciated.
A bit more information is needed. What do you want to place in the admin resource? Only posting, or also editing?
But a few tips to get started:
- You have to split your posts-controller. Make a subfolder in the controllers called admin (the resource name). Move the admin-functions to this controller, and leave the public posts-function (index and show) in the normal posts_controller.
- Do the same for the views.
And, i suspect you want the routes to be:
namespace :admin
resources :posts
end
get '/:id', :to => 'posts#show'
root :to => 'posts#index'
Then you can put some form of authentication to the admin namespace.
Hope this helps you on the way.

Unable To Access Public Images Possible Routing Issue

I'm working on a project and trying to render some images sitting under the public directory in one of my show views. I'm able to access these images just fine on my index view, but it's not quite so easy for show views it would seem.
So lets say in my view I have something like the following:
<%= "<img src=\"images/16x16/actions/filesave.png\" class=\"icon" title=\"save\">"%>
This would work in my index view perfectly fine, but for some strange reason I get this routing error in my show view:
ActionController::RoutingError (No route matches [GET]
"/uploads/images/16x16/actions/filesave.png"):
I noticed that for some peculiar reason it's injecting the "/uploads/" route right before the "/images..." this is the cause of my problem and I can't figure out why or how to stop it. This only happens with my show views.
Now there's a lot going on in my routes.rb file, I know it's ugly but I do plan on going in there and cleaning it up when I get the chance.
resources :upload_images
get "upload_image/new"
get "upload_image/index"
get "upload_image/show"
get "upload_image/delete"
resources :help_categories
resources :global_configs
resources :competitions
match '/teams/register', :controller => 'teams', :action => 'register'
match '/teams/invite_users', :controller => 'teams', :action => 'invite_users'
match '/teams/view_invitations', :controller => 'teams', :action => 'view_invitations'
match '/teams/ignore', :controller => 'teams', :action => 'ignore'
match '/teams/leave_team', :controller => 'teams', :action => 'leave_team'
resources :teams
resources :competitions do
resources :matches
end
resources :registers
resources :players do
collection do
post :edit_individual
put :update_individual
get :results
end
end
resources :tournaments
resources :matches
resources :upload_categories
resources :uploads, :except => [:new]
match '/download/:id' => 'uploads#download'
devise_for :users do
match 'logout' => 'devise/sessions#destroy'
end
resources :users, :except => [:new] do
member do
get 'upload_files'
get 'delete_files'
end
end
resources :games
devise_for :videolinks
resources :topics do
collection do
get "mark_all_viewed"
end
member do
get 'show_new'
end
end
resources :posts do
member do
get 'quote'
get 'topic'
end
end
resources :forums do
member do
get 'confirm_delete'
end
end
resources :blog_entries, :except => [:index]
resources :categories
resources :videolinks
resources :competition_games
resources :competitions
resources :news
resources :events
match 'uploads/find_uploads' => 'uploads#find_uploads'
match 'uploads/add_upload_image' => 'uploads#add_upload_image'
match 'forum_root' => 'forums#index'
match 'upload_root' => 'uploads#index'
match 'user' => 'forums#index'
match 'news_root' => 'news#index'
match 'topic_post' => 'forums#index'
match 'quote_post' => 'forums#index'
match 'new_upload' => 'forums#index'
match 'videolinks/:id', :to => 'videolinks#show'
match 'register' => 'users#sign_up'
match 'login' => 'users#sign_in'
match 'users/find_users' => 'users#find_users'
match '/users/get_states/:country' => 'users#states'
match '/ban/:username' => 'users#ban'
match '/ban_user/:username' => 'users#ban_user'
match ':username' => 'users#show'
match ':username/edit' => 'users#edit'
match ':username/delete_files_all' => 'uploads#index'
match ':username/delete_files' => 'users#delete_files'
match ':username/upload_files' => 'users#upload_files'
match ':username/password/edit' => 'users#editpass'
match ':username/edit_file/:id' => 'uploads#edit'
match '/maketakeadmin/:username' => 'users#maketakeadmin'
match ':username/destroy' => 'users#destroy'
root :to => "home#index"
resources :categories do
member do
get 'confirm_delete'
end
end
Another developer worked on the upload section of this application and it uses paperclip. By default it saves uploads in the public directory and we didn't want that so he told me he did some weird hotfix to save uploads to a private directory off of the root of the application called "uploads". Not sure if this might have anything to do with it.
Needed a forward slash at the start of the path.
I think you should use something like this:
<%= image_tag "/images/16x16/actions/filesave.png", class: "icon", alt: "save" %>

Rails 3.1 subdomain based controller routing

I'm currently getting the error:
No route matches [GET] "/tenant_admin"
I was using something like:
http://example.com/accounts/1/tenant_admin
but I'm now passing the account id as a subdomain;
http://AccountName.example.com/
Is it possible to make the url work like this:
http://AccountName.example.com/tenant_admin ?
Routes.rb
get "log_out" => "sessions#destroy", :as => "log_out"
get "log_in" => "sessions#new", :as => "log_in"
get "sign_up" => "users#new", :as => "sign_up"
resources :users
resources :sessions
resources :password_resets
resources :accounts do
resources :tenant_admin
end
constraints(Subdomain) do
match '/' => 'accounts#show'
end
root :to => "welcome#index"
You have to put your tenant routes under resources :accounts and constraints(Subdomain). I don't recommend using copy and paste but a lambda instead.
tenant_routes = lambda do
resources :tenant_admin
end
resources :accounts do
tenant_routes.call
end
constraints(Subdomain) do
tenant_routes.call
end

Resources