ruby on rails - Checkbox is cleaning after searching -


i did application using checkbox options after doing click on search cleaning checked , starting checked (is not saving last checked clicked).

here table

|people|   |id|    |name|   |state|    1       abc       0    2       def       0      3       def       1    4       def       1 

here controller:

class personcontroller < applicationcontroller    def search     @people = person.find(:all,:conditions=>['state = ?',params[:state] ] )   end  end 

here view:

 <% form_tag :controller=>"person",:action=>"search" %>     single  <%= check_box_tag "state", "0", params[:state] %>     married <%= check_box_tag "state", "1", params[:state] %>     <%= submit_tag "search", :name => nil %>  <% end %>   <% @people.each |p|  %>     p.name     p.state  <% end %> 

i tried:

    single  <%= check_box_tag "state", "0", params[:state].to_i %>     married <%= check_box_tag "state", "1", params[:state].to_i %> 

and tried too:

    single  <%= check_box_tag "state", 0, params[:state].to_i %>     married <%= check_box_tag "state", 1, params[:state].to_i %> 

and this:

    single  <%= check_box_tag "state", "0", params[:state] %>     married <%= check_box_tag "state", "1", params[:state] %> 

everytime click on search, check option cleaning , isn't saving checked did.

the checkbox isn't saving checked after doing search.

please can me?

syntax checkbox tag is

check_box_tag(name, value = "1", checked = false, options = {}) 

so in third parameter have pass either true or false, depending on params check or uncheck checkbox.

try this

single  <%= check_box_tag "state", "0", params[:state].to_s == '0' %> married <%= check_box_tag "state", "1", params[:state].to_s == '1' %> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -