Last active
January 13, 2016 14:11
-
-
Save LolWalid/9467347e26c707286d07 to your computer and use it in GitHub Desktop.
Beautiful routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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