rails4 ckeditor (No route matches [POST] "/ckeditor/ - ruby-on-rails

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.

Related

Rails 5 rename CRUD route

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

Does the order of the routes effect which controller is accessed?

In my app I have grants and I want the url to be root/grant_id instead of root/grants/grant_id. I have this in my routes
Rails.application.routes.draw do
...
root 'static_pages#welcome'
# get 'home' => 'static_pages#home'
get 'about' => 'static_pages#about'
get 'faq' => 'static_pages#faq'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
get 'dashboard' => 'dashboard#index'
resources :users do
resources :projects
member do
get 'access_granted'
put 'access_granted'
get 'remove_access'
put 'remove_access'
end
end
resources :profiles
resources :account_activations, only: [:edit]
resources :password_resets, only: [:new, :create, :edit, :update]
resource :request_access, only: [:show, :new, :create]
resources :grants, :path => '' do
resources :app_types do
resources :submissions
end
end
get 'grants' => 'grants#index'
resources :matches
end
When I put resources :matches below the resources :grants, :path => '' do line I get the error "Couldn't find Grant" and I see that request parameters are
{"controller"=>"grants", "action"=>"show", "id"=>"matches"}. When I put resources :matches above the the grant line everything works fine. Its almost like something in the grant route isn't closing and is forcing any lines below it to look for the grant controller. A simple solution is just keeping everything above that line but I'm trying to understand why this is happening.
I also noticed that even though I define the grant#index as grants, when I rake routes I see:
grants GET / grants#index
GET /grants(.:format) grants#index
So two questions
1. Is :path => '' the correct way to remove the grants/ part of the url.
2. Why is everything below the grants route getting sent to the grants controller?
From the documentation :
Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action's route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.
So, the problem you're having is that matching grants to "" means your grants INDEX route is /, and your grants SHOW route is /:grant_id, which will match any route. If you want to have this kind of route (which I would advise against), it has got to be at the bottom of the routes file.
You can read more about routing here: http://guides.rubyonrails.org/routing.html

Dynamic Routes Settings In Ruby on Rails Like Facebook

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

Hot to redirect "example.com/////" to just "example.com" in Rails app?

My goal is when user requests root (AND ONLY ROOT, other pages work fine) with something like:
http://domain.com/////
http://domain.com//////////////
http://domain.com//
app should 301 redirect user to one and only correct:
http://domain.com/
I'm using Webrick, rack-rewrite gem and planning to host it on Heroku.
Please remember that i'm new in Rails.
UPDATE ======
Rails: redirect all unknown routes to root_url
— this is totally different problem. They just redirect all unknown hosts to root. I have 404 working normally.
My problem is that any amount of slashes works as homepage and URL has all of those slashes. I'm doing it for SEO to get rid of duplicates of homepage. I want it to work like here: http://netpeak.ua (try "netpeak.ua////////", you will be redirected to "netpeak.ua").
UPDATE 2 - added content of routes.rb ======
Rails.application.routes.draw do
resources :questions
resources :feedbacks
devise_for :users
get '' => 'public#index'
get '/agency' => 'public#about'
get '/contact' => 'public#contact'
get '/uslugi' => 'services#index'
get '/portfolio' => 'projects#index'
get '/uslugi/:id' => 'services#show'
get '/portfolio/:id' => 'projects#show'
resources :articles, param: :id
resources :settings, as: 'home' #home so it doesn't go to another page
namespace :admin do
resources :articles, :users, :projects, :services, :feedbacks, :questions
get '' => 'projects#index'
get 'contact' => 'settings#contact'
get 'feedback' => 'settings#feedback'
get 'fininfo' => 'settings#fininfo'
get 'calls' => 'settings#calls'
get 'orders' => 'settings#orders'
get 'letters' => 'settings#letters'
get 'allquestions' => 'settings#allquestions'
get 'projectsettings' => 'settings#projectsettings'
get 'servicessettings' => 'settings#servicessettings'
get 'aboutsettings' => 'settings#aboutsettings'
get 'startpagesettings' => 'settings#startpagesettings'
patch 'contact' => 'settings#update'
patch 'feedback' => 'settings#update'
patch 'fininfo' => 'settings#update'
patch 'projectsettings' => 'settings#update'
patch 'servicessettings' => 'settings#update'
patch 'aboutsettings' => 'settings#update'
patch 'startpagesettings' => 'settings#update'
end
end

Whenever I scope the routes.rb I get an error in my rails app

I am trying to implement internationalization as seen in railscasts, and every time I scope my routes file I get the error
No route matches [GET] "/"
or the error
missing :controller
config/routes.rb:6:in `block (2 levels) in <top (required)>'
config/routes.rb:5:in `block in <top (required)>'
config/routes.rb:1:in `<top (required)>'
Here is my routes.rb file
Jensenlocksmithing::Application.routes.draw do
get "log_out" => "sessions#destroy", as: "log_out"
get "log_in" => "sessions#new", as: "log_in"
scope ":locale" do
get "site/home"
get "site/about_us"
get "site/faq"
get "site/discounts"
get "site/services"
get "site/contact_us"
get "site/admin"
get "site/posts"
root :to => 'site#home'
end
#match '*path', to: redirect("/#{I18n.default_locale}/%{path}")
#match '', to: redirect("/#{I18n.default_locale}")
match "/savesort" => 'site#savesort'
resources :users
resources :abouts
resources :sessions
resources :coupons
resources :monthly_posts
resources :reviews
resources :categories do
collection { post :sort }
resources :children, :controller => :categories, :only => [:index, :new, :create, :new_subcategory]
end
resources :products do
member do
put :move_up
put :move_down
end
end
resources :faqs do
collection { post :sort }
end
end
So, why whenever I add the scope ":locale" do end line do I get these errors? It all works fine without. Let me know if you need to see any more code. Thanks guys
Edit
In my application controller I have the following:
private
def default_url_options(options = {})
{locale: I18n.locale}
end
Does this do the same thing as the passing the hash in the routes?
Edit 2
I changed my route to the following as seen in this gist.
https://gist.github.com/2322844
So why is the :id part being added to the get route? like this one
about_us_site GET /sites/:id/about_us(.:format)
shouldn't it be something like this
about_us_site GET /sites/about_us(.:format)
Also added my entire routes.rb file and the routes it generates for more information.
https://gist.github.com/2322861
Answer for anyone interested:
I changed
get "site/home"
get "site/about_us"
get "site/faq"
get "site/discounts"
get "site/services"
get "site/contact_us"
get "site/admin"
get "site/posts"
root :to => 'site#home'
to
resources :sites, except: [:new, :edit, :index, :show, :update, :destroy, :create] do
collection do
get :home
get :about_us
get :faq
get :discounts
get :services
get :contact_us
get :admin
get :posts
end
end
Passing in a hash should fix your routes:
scope "(:locale)", :defaults => { :locale => "en" } do
resources :sites
end
Also, you may want to consider creating a SitesController and giving it members:
resources :sites do
member do
get :about_us # Points to /sites/about_us
end
end
Rails Guides on Defining Defaults In Routes

Resources