seledted option for select_tag

Hi iam using select_tag i want selected_option. i have made select _tag like this

<%=select_tag('name', options_for_select({ :Relevance =>'Relevant',:Date=>'Recent'}),:selected=>params[:name].to_s) %>

The generated html look like this

<select selected="Relevant" name="name" id="name"><option value="Recent">Date</option> <option value="Relevant">Relevance</option></select>

How to make the selected option inside option tag

Hi iam using select_tag i want selected_option. i have made select _tag like this

<%=select_tag('name', options_for_select({ :Relevance =>'Relevant',:Date=>'Recent'}),:selected=>params[:name].to_s) %>

The generated html look like this

<select selected="Relevant" name="name" id="name"><option value="Recent">Date</option> <option value="Relevant">Relevance</option></select>

How to make the selected option inside option tag

Well since selectedness is a property of an option not the select tag as a whole it makes sense for it to be an argument to options_for_select. Check the api for options_for_select

Fred/