English 中文(简体)
铁路3条线路以外的使用变量
原标题:Use variable other than :id in rails 3 routes

我试图带走我铁路三号车,用一条像:

exampleapp.com/patients/123456

而不是

exampleapp.com/patients/1

如果“123456”与病人的医疗记录编号(:mrn)有关,该编号已载于<编码>:patients表,并且是一种独特的分类。 我想使用<代码>:mrn取代通常的<代码>:id。 我怎么办?

如果有人问这个问题,我无法找到我想要做什么的术语。 页: 1

最佳回答

你可以把这一点补充到你们的病人模式中。

def class Patient < ActiveRecord::Base
  self.primary_key = "mrn"  
end
问题回答

你可以这样做,

class Patient < ActiveRecord::Base
  self.primary_key = "mrn"
end

然而,这将改变其他事物的bu。 to子将使用rn。 管制人员仍将使用“伞式”器,但其价值将是小面积。 病人。 寻找办法将在大街区开展工作,而不是在田间工作。 (You canuser Patient.find_by_mrn and Patient.find_by_id, which will work on their specified areas.) 此外,所有外国钥匙都将达到微薄的价值。

You can edit the mrn field, and you will still have an id field (unless you turn it off), however, editing could be a pain because all the foreign keys will have to be corrected.

或者,如果你只是想改变《欧洲刑法》,那么,你就会把《欧洲刑法》改写在你身上。 rb 而不是

resources :patient

use

match "/patients/:mrn" => "patients#show"
match "/patients/:mrn" => "patients#update", :via => :put

可以通过重新定义成员——范围,在资源方面采用广域方法,实现对资源识别的定制。

resources :patients do
  @scope[:scope_level_resource].tap do |u|
    def u.member_scope
      "#{path}/:mrn"
    end

    def u.nested_scope
      "#{path}/:#{singular}_mrn"
    end
  end
end




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签