私は、複数の登録(診断、患者、検査室検査、サービス、クライアント、ユーザー、サプライヤ)。最初に、これらはデータベースをシードすることによって作成されます。 2.現在Iでデータ入力ユーザRails 3 - 外部クラスのbefore_saveコールバックのcheck_box_tag(モデルの一部ではない)に基づく説明の変更方法
によって指定された - の要件のいずれか 1.アプリケーション(まだ決定するために、いくつかの構成設定)によって指定された記述コードを混合するためのケース(大文字最初の単語)であります現在、私はbefore_saveコールバックを使用してい 1.コード(常に大文字する) 0002(最初のワードがcheck_box_tag値に基づいて大文字)
:2つのフィールドが含まれている診断のためのモデル、ビュー&コントローラを有していますモデルを変換を実装するが、私はそれがcheck_box_tagが選択されていないときにのみ働くようにすることはできません。つまり、check_box_ta g。
check_box_tagをcheck_boxに変更して、attr_assessorをモデルに追加しようとしましたが(格納する必要はないため、sqlite3 dbは含まれません)。
これも機能しませんでした。
どうすればよいですか?内部アプリケーション構成ファイルのチェックボックスを使用するオプションを無効にすると、アプリケーション構成でユーザーが選択できないことが指定されている場合、チェックボックスが「使用不可」または表示されなくなります。
モデル(diagnosis.rb)DescriptionHelper.rbで
require 'DescriptionHelper'
class Diagnosis < ActiveRecord::Base
attr_accessible :code, description
string_correct_case = DescriptionHelper.new([:code, :description])
validates :code, :presence => true, :length => { :minimum => 4, :maximum => 4 }
validates :description, :presence => true
before_save string_correct_case
end
コールバック
class DescriptionHelper
def initialize(attribute)
@attrs_to_manage = attribute
end
def before_save(record)
@attrs_to_manage.each do |attribute|
record.send("#{attribute}=", capitaliseWords(record.send("#{attribute}")))
end
end
private
def capitaliseWords(value)
value = value.mb_chars.downcase.to_s.gsub(/\b\w/) { |first| first.upcase }
end
end
コントローラ(diagnoses_controller.rb)
class DiagnosesController < ApplicationController
def new
@diagnosis = Diagnosis.new
end
def create
@diagnosis = Diagnosis.new(params[:diagnosis])
if @diagnosis.save
flash[:notice] = "Diagnosis created with params [#{@diagnosis.attributes.inspect}" #for debugging, once fixed will be just 'Diagnosis created.'
redirect_to @diagnosis
else
flash[:alert] = "Diagnosis not created."
render :action => "new"
end
end
.. other controller actions - edit, show, destroy
end
ビュー(_form.html.erb)
<%= form_for(@daignosis) do |f| %>
<div class="field">
<%= f.label :code %>
<%= f.text_field :code %>
</div>
<div class="field">
<%= f.label :description %>
<%= f.text_field :description %>
</div>
<div class="field">
<%= check_box_tag("diagnosis_desc_dont_convert", 1, false) %><%= f.label "Leave as entered" %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
これが現在実行されている場合、check_box_tagは無視されます。
モデルにattar_assessor:description_correctcaseを追加し、f.check_box 'description_correctcase'を使用するようにビューを変更すると、これは引き続き無視されます。
これはどのように機能するのですか?
事前にレール開発者を歓迎してくれてありがとうございます。