Forum: Ruby on Rails Help with this comparison and loop

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Buntin, Seth - KATE (Guest)
on 2006-03-02 18:07
(Received via mailing list)
I am sending this information:

      <%= observe_field "resource_focus_id",

         :frequency => 0.25,

         :url => { :action => :add_sub_focus},

         :with => "'focus_id='+ value +
'&sf_id=#{@resource.sub_focus_id}'",

         :update => "resource_sub_focus_id" %>



Which turns out to be:

<script type="text/javascript">
//<![CDATA[
new Form.Element.Observer('resource_focus_id', 0.25, function(element,
value) {new Ajax.Updater('resource_sub_focus_id',
'/kate/tick/admin/add_sub_focus', {asynchronous:true, evalScripts:true,
parameters:'focus_id='+ value + '&sf_id=2'})})
//]]>
</script>

All is good.  Now in my controller I have:

  def add_sub_focus
    @sub_focuses = SubFocus.find_all_by_focus_id(@params["focus_id"])
    @sf_id = @params["sf_id"]
  end



My add_sub_focus.rhtml file:



<% for sub_focus in @sub_focuses do -%>

    <% if #{sub_focus.id} != #{sf_id} %>

          <option value="<%= sub_focus.id %>">

             <%= sub_focus.name %>

          </option>

    <% else %>

          <option value="<%= sub_focus.id %>" selected="selected">

             <%= sub_focus.name %>

          </option>

    <% end %>

<% end -%>



Why does the option with the value of "2" not get selected?  I know for
sure that that value is present.



If I do this:



<% for sub_focus in @sub_focuses do -%>

    <% if #{sub_focus.id} == #{sf_id} %>

          <option value="<%= sub_focus.id %>" selected="selected">

             <%= sub_focus.name %>

          </option>

    <% else %>

          <option value="<%= sub_focus.id %>">

             <%= sub_focus.name %>

          </option>

    <% end %>

<% end -%>



I think every option gets selected because the last option is display
(as selected) and that isn't the value that should be selected.



Thanks.

Seth
This topic is locked and can not be replied to.