I have the following Rails 5 resources, and I want the URL to show /welcome on huddles#index (as well as for the huddles_path url helper). e.g, I don't want huddles_welcome_path. Can this be done? Thank you!
resources :huddles do
get '/welcome', to: 'huddles#index'
resources :invitations
end
Move the route outside of the huddles resource if you don't want to include huddles/ in the route:
resources :huddles do
resources :invitations
end
get '/welcome', to: 'huddles#index'
resources :huddles do
get '/welcome', to: 'huddles#index', :as => :huddles_path
resources :invitations
end
Just Add a :as => :namethatyouwant
Related
I currently have a default devise set up and wanting to put the user id's within my logged in routes and leave the others alone such as Welcome,FAQ, About us etc.
Such as
www.example.com/user-id/offers
My Current Routes File
devise_for :users
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
resources :offers do
member do
put :tourcomplete
end
end
resources :categories, only: :show
root 'welcome#index'
get '/balance', to: 'balance#show', as: 'balance'
patch '/balance', to: 'balance#paypal', as: 'balance_paypal'
patch '/withdraw', to: 'balance#withdraw', as: 'balance_withdraw'
I can't find any docs on this and my previous answer to a similar question was very vague and not helpful.
Thanks
You will need to use a nested routes:
resources :users do
resources :offers do
member do
put :tourcomplete
end
end
end
so now your routes will be /users/:id/offers, run rake routes to check your routes.
if you want to exclude users then you will have to specify the route yourself:
match ':user_id/offers' => 'offers#index'
Current routes has been defined as:
Rails.application.routes.draw do
namespace :users do
resources :mapps
resources :listings
resources :likes
get 'followers' => 'connections#followers'
get 'following' => 'connections#following'
post 'unfollow' => 'connections#unfollow'
end
get ':username' => 'users#public_profile'
end
I would like make routes like facebook:
:username/:controller/:action => users/:controller/:action
For example, If user hit a URL as /myusername/posts/12 then request must goes to controller file inside user folder & User:Posts
I have seen many related questions but did not work with Rails 4.2.3
An example from http://guides.rubyonrails.org/routing.html#prefixing-the-named-route-helpers
scope ':username' do
resources :mapps
resources :listings
resources :likes
get 'followers' => 'connections#followers'
get 'following' => 'connections#following'
post 'unfollow' => 'connections#unfollow'
end
I have installed Rails4 (rails (4.1.1))
I Installed Ckeditor+paperclip (http://rubydoc.info/gems/ckeditor/4.0.11/frames)
But if I try to upload images, I get this error in log:
ActionController::RoutingError (No route matches [POST] "/ckeditor/EDITOR.config.filebrowserImageUploadUrl"):
i need help please! This was worked In rails 4.0.0.
My route list
... mount Ckeditor::Engine => '/ckeditor'
I use Ckeditor with Paperclip
My config/routes.rb
Rails.application.routes.draw do
resources :binaries
resources :uploads
resources :coms
resources :comments
mount Ckeditor::Engine => '/ckeditor/'
resources :parts
get "/parts/page/:id" => "parts#page"
resources :answer_types
resources :from_sender_msgs
resources :ufknews
get "/general" => "ufknews#general"
get 'ufk13/ufk13pol'
get 'ufk13/governance'
get 'ufk13/contacts'
get "errors/error_404"
get "errors/error_403"
devise_for :users
devise_scope :user do
get "sign_in" => "devise/sessions#new"
get "logout" => "devise/sessions#destroy"
delete "logout" => "devise/sessions#destroy"
get "users" => "users#index"
get "users/:id" => "users#show" , as: :user_root, as: :user
get "users/:id/edit" => "users#edit" , as: :user_edit
get "users/delete" => "users#delete"
put "users" => "users#update"
end
get 'persons/profile'
resources :budget_types
resources :positions
resources :message_types
resources :message_states
resources :messages
resources :senders
resources :organisations
root 'ufknews#general'
get 'home/index'
get 'home/about'
get 'home/contacts'
get 'home/dufk'
get 'home/photo'
get "/*other" => redirect("/errors/error_404")
end
So, you can modify your routes to use POST request instead PUT while try to update data with ckeditor.
For example, if you have in your routes.rb:
resources :pages
you can update this to:
resources :pages, :except => ['update']
post 'pages/:id' => 'pages#update'
It's all!
This method kill a two rabbits:
Modify route for ckeditor;
Improve your project to update big fields over header size limits on your backend of client browser.
I want to replace the normal /users/:id route that is created by the resources command, with a more abstract /profile route. It won't be possible to view other users profiles in my app, and therefor the current route is unnecessary specific.
I have tried to overwrite the route created by 'resources :users' with:
get '/profile', to: 'users#show'
and other variances and combinations, but can't seem to get it right. Either the controller can't find the user because of a missing id or it simply can't find the route.
Thanks for the help!
You can use this code in routes.rb file:
resources :users, :except => :show
collection do
get 'profile', :action => 'show'
end
end
It will generate url "/users/profile".
But, if u want to use only '/profile', then don't create route as collection inside users resources block.
resources :users, :except => :show
get 'profile' => "users#show", :as => :user_profile
It will redirect '/profile' to show action in users controller.
I suggest simply adding a users/me route pointing to the show action of your UsersController like so:
resources :users, only: [] do
collection do
get 'me', action: :show
end
end
You can also use the match keyword in routes.rb file.
match 'users/:id' => 'users#show', as: :user_profile, via: :get
When I put the following code in my routes config :
resources :users do
end
I get all the CRUD operations routes. i.e
/users/new
/users/:id/edit
and so on.
How do I configure routes so I get route like this :
/users/lookup/:search_query
And when users reaches this routes he/she should be taked to lookup method of my controller
I would do :
resources :users do
get :lookup, on: :collection
end
And I would pass the search_query as a parameter. With that you will be more flexible.
resources :users do
get '/lookup/:search_query' => 'users#lookup', on: :collection
end
resources :users do
end
match '/users/lookup/:search_query' => "users#lookup", :as => :user_lookup