我有這三個底部路線半寧靜的路線是因爲通常申報等航線的很容易出錯:Rails的:低於
# normal routes
resources :documents, :except => [:show, :edit, :update]
resources :photos, :except => [:show, :index]
...
# error-prone routes
get ":client_code" => "share#index", :as => :shares, :format => false
get ":client_code/:id" => "share#show", :as => :share, :format => false
get ":client_code/:document_id/more/:component_id" => "share#more", :as => :more, :format => false
我得在ShareController
一些應對方法與像這樣的請求:
def show
get_user_by_parameter
if get_document_by_user_or_issue and @document.is_showable? and @parameter_user == @document.user
...
end
private
def get_user_by_parameter
@parameter_user = User.where(:client_code => params[:client_code]).first
end
def get_document_by_user_or_issue
if params[:id].match(/\D/)
@document = Document.where(:user_id => @user.id, :issue => params[:id]).first
else
@document = Document.find(params[:id])
end
end
我需要的路線是最小的,但是這不僅是醜陋和非RESTful的,但它是非常容易出錯。
:client_code
將始終是正在查看的@document
的所有者。這有點像安全檢查/擁有權有點功能。但是,由於上面列出的所有原因:是否有更好的方法來寫這個?有一個比這更好的方法。
謝謝。
基於
容易出錯?什麼? – phoet