Edit in place for select

Hi there,

I am struggling to have an edit in place field for a select control.
This select control picks its options from a database table.

Googling got me some code examples. But none of them worked for me.
They all seem to assume things. I’d appreciate if some body can point
me at a complete code listing or ways to get this done.

Thanks much in advance.

Thanks Tim. It worked.

To make things little neat, I moved this whole code into a helper
method that returns me a javascript code.

Hi ya

Try this…

###Â VIEW ###

Order Status
<%[email protected] %>

HELPER

def map_statuses(collection)
collection.map {|status| ‘[’ << status.id.to_s << ‘,’ <<
“’#{status.status_name.to_s}’” << ‘] ,’ }
end

CONTROLLER

@order_statuses = OrderStatus.find(:all)


I hope that helps

Cheers

Tim

To make things little neat, I moved this whole code into a helper
method that returns me a javascript code.

For sure :slight_smile: In the spirit of this forum post up your helper - it might
help somone in the future with any luck :wink:

Cheers

Tim P.

On Feb 28, 2007, at 8:18 AM, Love AJAX wrote:

Thanks Tim. It worked.

To make things little neat, I moved this whole code into a helper
method that returns me a javascript code.

If I might suggest a slight improvement:

HELPER

def map_statuses(collection)
collection.map {|status| [status.id, status.status_name] }.to_json
end

Then you don’t have to worry about the potential problem of quotes
within your status_name column. ('cause to_json will handle it for you)

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Here it is (modified to my needs):
#######################
def in_place_select_editor(options)
options[:ajax] = { :okText => “‘Save’”, :cancelText =>
“‘Cancel’”}.merge(options[:ajax] || {})
script = Array.new
script << “new Ajax.InPlaceCollectionEditor(”
script << " ‘#{options[:content][:options][:id]}’,"
script << " ‘#{url_for(options[:url])}’,"
script << " {"
script << " collection: #{options[:collection]},"
script << options[:ajax].map{ |key, value| “#{key.to_s}:
#{value}” }.join(", “)
script << “, ajaxOptions: {”
script << “method: ‘post’}”
script << " }”
script << “)”

 content_tag(
   options[:content][:element],
   options[:content][:text],
   options[:content][:options]
 ) + javascript_tag( script.join("\n") )

end
#######################

In view:

<%= in_place_select_editor( :content => {
:element => ‘span’,
:text => get_role_name(staff.login_id),
:title=> “”,
:options => {
:id => “user_role_name_#{staff.id}”,
:class => ‘editable-content’
}
},
:url => {
:controller => ‘user_lookup’,
:action => “set_permissiondata”,
:id => staff.login_id,
:fieldname => ‘role_id’
},
:ajax => {
:size => 15,
:value => “’” +
get_role_name(staff.login_id)+ “’”
},
:collection => roles
) %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs