railsプロジェクト学習

2526 ワード

Railsルーティング学習

'welcome', :action => 'say'} %>
( URL , , a )
hello

match '/:controller/:action/:id.:format'

:id params[:id] controller

.format .json、.xml , params[:format]


match '/meetings/:id' => 'events#show'
events controller show

match '/meetings' => 'events#index', :as=>"meetings"

meetings_path meeting_url Helper


root :to => 'welcome#show'
public/index.html

get 'account/overview' => 'account#overview'

id

match "events/show/:id" => "events#show", :constraints => {:id => /\d/}

ip

constrains(:ip=>/(127.0.0.1$)|(192.168.[0-9]{1,3}.[0-9]{1,3})$/) do
match '/events/show/:id' => "events#show"
end

Restful
resources :events do
resources :tasks, :people
end


resources :products do
collection do

products_controller.rb sold on_offer

get :sold
post :on_offer

end
end

Namespace

controller admin

namespace :admin do

admin projects_controller.rb

resources :projects
end

URL_Helper admin_projects_path

admin/projects/


###Request  
 controller     

request.action_name
request.cookies
request.headers
request.params
request.xhr? # Ajax
request.host_with_port
request.remote_ip
request.headers
request.session