how to set default value of select_tag in rails? instance variable -
i have controller action:
class candidatescontroller < applicationcontroller helper_method :current_or_guest_user def show # authorize! :read, @user @candidate = candidate.friendly.find(params[:id]) @candidates = candidate.all if request.path != candidate_path(@candidate) redirect_to @candidate, notice: 'moved permanently' end @comparison = usercomparisonservice.new(current_user, @candidate) @contact = contactcandidate.new(candidate_email: @candidate.email) end
this calls partial render on show page , passes @candidate instance variable:
= render 'users/compare', :candidate => @candidate
this form within partial:
profile-searchbar.text-left = form_tag(compare_path, method: 'get', remote: true, id: 'compare_form') = select_tag "v_friend_id", options_from_collection_for_select(@candidates, :id, :full_name, @comparison.v_friend.id), :include_blank => true, :class => "compare-search", :style => "width:100%; margin-left: 3px %a.compare_btn{:href => "javascript:void(0)"}
this select dropdown works candidate.all method in controller, how set default value of candidates @candidate, can take away dropdown / search , have compare candidate's page on?
this apidock
select_tag "people", options_from_collection_for_select(@people, "id", "name", "1")
and output is:
<select id="people" name="people"><option value="1" selected="selected">david</option></select>
as can see, id
passed fourth element on options_from_collection_for_select
instead of @comparison.v_friend.id
think have use @candidate.id
Comments
Post a Comment