How do I convert this dropdown to a f.select in Rails?

后端 未结 1 1497
走了就别回头了
走了就别回头了 2021-01-28 11:53

I\'m a Rails beginner and I\'m working on a preexisting Rails 2 project. In my application, I tried converting a select dropdown field to a form_handler f.select, but I\'m getti

相关标签:
1条回答
  • 2021-01-28 12:34

    Place the following in a helper file

    def select_options_for_locations(locations)
      locations.map do |location|
        [location_string(location.masterlocation), location.masterlocation.street_address]
      end
    end
    
    def location_string(masterlocation)
      "#{masterlocation.city}, #{masterlocation.state}, #{masterlocation.zip} #{masterlocation.name}"
    end
    

    Then in your view, you can use the following

    = f.select :start, select_options_for_locations(@itinerary.locations),  {}, :id => "startdrop"
    
    0 讨论(0)
提交回复
热议问题