Rails routing – :on => :collection

Routes on collections are listed here. The difference between :on => :collection and :on => :member are the style of route they produce and their associated route helpers. resources :posts do # on collection get ‘search’, on: :collection # –> generates ‘/posts/search’ and search_posts_path # on member get ‘share’, on: :member # –> generates’/posts/:id/share’ and … Read more

Adding an action to an existing controller (Ruby on Rails)

The error you’re making is actually a pretty common one. Basically, Rails automatically maps URLs for your scaffolds. So when you created the Posts scaffolds, Rails is mapping the URL routes for it. One such route is the URL for viewing a single post: /posts/(post_id) So, when you’re entering the URL /posts/start Rails thinks you’re … Read more

How to add custom routes to resource route

Add this in your routes: resources :invoices do post :send, on: :member end Or resources :invoices do member do post :send end end Then in your views: <%= button_to “Send Invoice”, send_invoice_path(@invoice) %> Or <%= link_to “Send Invoice”, send_invoice_path(@invoice), method: :post %> Of course, you are not tied to the POST method

Rails Responds with 404 on CORS Preflight Options Request

Here’s a solution with the rack-cors gem, which you said you tried. As others have mentioned, you didn’t give much detail in regards to which front-end framework you’re using and what the actual request looks like. So the following may not apply to you, but I hope it helps someone. In my case, the gem … Read more

Routes with Dash `-` Instead of Underscore `_` in Ruby on Rails

With Rails 3 and later you can do like this: resources :user_bundles, :path => ‘/user-bundles’ Another option is to modify Rails, via an initializer. I don’t recommend this though, since it may break in future versions (edit: doesn’t work in Rails 5). Using :path as shown above is better. # Using private APIs is not … Read more

tech