How to compare Rails Form Parameters? -


so making program has script "set of steps complete task" can applicable stores or select few. stores option boolean value gets stored script. when select "yes" stores should remove stores associated script if there any. script , store tables have habtm relationship. question how check inside parameter see if value of all_stores true? have tried few things , seems ignore if statement compare stores parameter true

script controller

  def update     params[:script][:store_ids] ||= []     if params[:script][:all_stores] == true       params[:script][:store_ids] = []     end     @script = script.find(params[:id])     if @script.update_attributes(params[:script])       flash[:notice] = 'script updated'       redirect_to :action => 'index'     else       @categories = category_search       render :action => 'edit'     end   end 

script edit view

<%= form_for(:script, :url => {:action => 'update', :id =>@script.id}) |f| %>     <div id="script_form_visibility">         <div class="issue_section_header" align="center">visibility</div>         <div class="line-break"></div>         <div class="standardtext"><span class="boldtext">all stores:</span> <%=f.radio_button(:all_stores, true)%> yes <%=f.radio_button(:all_stores, false)%> no</div>         <br/>         <div class="issue_section_header" align="center">stores</div>         <div class="line-break"></div>         <div class="standardtext">             <%@stores.each |store|%>                 <%= check_box_tag 'script[store_ids][]', store.id, @script.store_ids.include?(store.id), :id => dom_id(store) %>                 <%= label_tag dom_id(store), store.name, :class => "check_box_label" %><br/>             <%end%>         </div>     </div>     <div id="script_form">         <div class="boldtext"><%= f.label :name %></div>         <div><%=f.text_field :name, :size => '94', :maxlength => '70'%></div>         <div>             <table width="100%" cellspacing="0">                 <tr>                     <td class="boldtext"><%= f.label :category_id, "category" %></td>                     <td class="boldtext" align="right">show id required field</td>                 </tr>                 <tr>                     <td class="standardtext"><%=f.select(:category_id, @categories.collect {|c| [c.name, c.id]}, :selected => session[:admin_category])%></td>                     <td class="standardtext" align="right"><%=f.radio_button(:require_id, true)%> yes <%=f.radio_button(:require_id, false)%> no</td>                 </tr>             </table>         </div>         <div class="boldtext"><%= f.label :task %></div>         <div><%= f.text_area(:task, :size => "68x20") %></div>         <div class="boldtext"><%= f.label :expected_results, "expected results" %></div>         <div><%= f.text_area(:expected_results, :size => "68x20") %></div>         <div align="center"><%= f.submit "update script" %></div>     </div> <% end %> 

problems solved in rails debugger. fire , set breakpoint @ line:

if params[:script][:all_stores] == true 

when reach breakpoint example contents of params hash

(rdb:3) p params[:script][:all_stores] 

this tell why code isn't behaving expected.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -