0
現在のソリューションでは、2つの異なる変数名を持つ両方の値をビューからコントローラに渡し、次にコントローラのロジックを使用して、どちらを使用して更新を行うかを決定します。それは機能しますが、よりよい方法が必要だと私は考えています。何かアドバイス?選択リストまたは同じフォーム(Rails 3)のテキストフィールドから同じ値を更新するにはどうすればよいですか?
===ビュー===
<p>Choose tutor from list: <%= f.collection_select(:current_tutor, @tutors,
:name, :name, {:include_blank => true}) %></p>
<p>..or dd new tutor: <%= f.text_field :current_tutor_textfield %></p>
===コントローラ===
respond_to do |format|
@student = Student.where(:slug => params[:id]).first
# Here I'm deciding which value will be passed to the update as the new_tutor
unless params[:student][:current_tutor].blank?
new_tutor = params[:student][:current_tutor]
end
unless params[:student][:current_tutor_textfield].blank?
new_tutor = params[:student][:current_tutor_textfield]
end
if @student.update_tutor(new_tutor)
format.html { redirect_to(students_path,
:notice => 'Student was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @post.errors,
:status => :unprocessable_entity }
end
end
これは... "新しいチューターの名前は、既存のチューターの選択を上書きします" ...まさに何が起こるのですか? –