Skip to content

Instantly share code, notes, and snippets.

@LolWalid
Last active January 13, 2016 14:11
Show Gist options
  • Save LolWalid/9467347e26c707286d07 to your computer and use it in GitHub Desktop.
Save LolWalid/9467347e26c707286d07 to your computer and use it in GitHub Desktop.
Beautiful routes
# params[:id] || params[:my_model_id]
# routes.rb
MyApp::Application.routes.draw do
resources :my_models do
collection do
get :search # GET /my_models/search(.:format)
end
member do
post :disable # POST /my_models/:id/disable(.:format)
end
end
end
# my_models_controller.rb
class MyModelsController < ApplicationController
def search
@models = MymModel.search(params[:search])
# blablabla
end
def disable
@model = MyModel.find(params[:id])
# blablabla
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment