Topic: in_place_editor_field to create a dropdown

I want to use the in_place_editor feature to edit my data. but on of the column is a foreign_key to another table. so, for this particular column, I'd like in_place_editor_field to display a dropdown containing a list of valid values.

anyone ever done that? what would be the best way?

Re: in_place_editor_field to create a dropdown

The Rails Recipe book shows you how to do this exact thing (the Making Your Own JavaScript Helper chapter). Unfortunately the process is too involved for me to write it all here. I also don't want to copy it right out of the book. I recommend getting the book, it's worth it.

Railscasts - Free Ruby on Rails Screencasts

Re: in_place_editor_field to create a dropdown

there is already an Ajax.InPlaceCollectionEditor in actionpack-1.12.5/lib/action_view/helpers/javascripts/controls.js

demo can be previewed here.
http://wiki.script.aculo.us/scriptaculo … ion+Editor

so I only need to write some ruby to use it, no js required wink

Re: in_place_editor_field to create a dropdown

Wow, nice to know!

Railscasts - Free Ruby on Rails Screencasts

Re: in_place_editor_field to create a dropdown

I am using the in_place_select_editor recipe from the Pragmatic Programmer Rails Recipe Book.  I am not seeing the position name (only the position_id). How can I see the see the name on the view?  When I click to edit it shows the names in the pull down correctly.  I seem to break it whenever I change :position_id to something else.

Thank you for any help.

View

<%for player in @player_sports -%>
<%@player_sport = player%>
<%@player = player.player%>
<%=in_place_editor_field :player, :first_name%>
<%=in_place_editor_field :player, :last_name%>
<%=in_place_select_editor_field( :player_sport, :position_id, {}, :select_options => options_for_select(Position.find_all_by_sport_id(player.team.sport_id).collect {|p| [ p.name, p.id ] }) )%>
</p>
<%end%>

Controller
in_place_edit_for :player, :first_name
in_place_edit_for :player, :last_name
in_place_edit_for :player_sport, :position_id

Tables
class CreatePlayerSports < ActiveRecord::Migration
  def self.up
    create_table :player_sports do |t|
      t.column :player_id,  :integer
      t.column :team_id,    :integer
      t.column :position_id,:integer
      t.column :number,      :integer
      t.column :active,     :boolean
    end
  end

class CreatePositions < ActiveRecord::Migration
  def self.up
    create_table :positions do |t|
      t.column :name,      :string
      t.column :sport_id,  :integer
      t.column :sort,      :integer
    end
  end