How do I update the same value from either a selection list or a textfield on the same form (Rails 3)? -


my current solution involves passing both values 2 different variable names view controller , using logic in controller decide 1 use update. works, i'm thinking there has better way. advice?

=== view ===

<p>choose tutor list:&nbsp;<%= f.collection_select(:current_tutor, @tutors, :name, :name, {:include_blank => true}) %></p> <p>..or dd new tutor:&nbsp;<%= f.text_field :current_tutor_textfield %></p> 

=== controller ===

respond_to |format|      @student = student.where(:slug => params[:id]).first       # here i'm deciding value passed update 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 updated.') }        format.xml  { head :ok }      else        format.html { render :action => "edit" }        format.xml  { render :xml => @post.errors,                  :status => :unprocessable_entity }      end end 

i don't know of lot of better ways it, though i'd clean bit you're deciding tutor goes @student. 2 statements mutually exclusive, no? both execute @ point, unless intent new tutor name override selection of existing tutor.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -