# Acts as drop down

**URL:** <https://www.ruby-forum.com/t/acts-as-drop-down/94318>\
**Category:** Rails\
**Created:** [April 28, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/acts-as-drop-down/94318 "2006-04-28T17:24:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 28, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/acts-as-drop-down/94318/1 "2006-04-28T17:24:17Z")

</div>

Hi

Im using the acts as drop down plugin

and have this code below

acts\_as\_dropdown :text =\> “forename”, :order =\> “forename”

It currently makes use of the forename in the option tag, how can I get  
it to use the surname as well

ie somthing like ‘forename’ . ‘surname’ in php

Thanks

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 9, 2006, 10:37am UTC](https://www.ruby-forum.com/t/acts-as-drop-down/94318/2 "2006-06-09T10:37:17Z")

</div>

still stuck on this one,

I need the select box to show both forename and surname, any  
suggestions?

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 9, 2006, 11:25am UTC](https://www.ruby-forum.com/t/acts-as-drop-down/94318/3 "2006-06-09T11:25:43Z")

</div>

I think you can create a method in your model

def full\_name  
“#{self.forename}, #{self.surname}”  
end

and then you can use the acts\_as\_drop\_down as

acts\_as\_dropdown :text =\> :full\_name, :order =\> “forename”, :value =\>  
:id

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 9, 2006, 11:43am UTC](https://www.ruby-forum.com/t/acts-as-drop-down/94318/4 "2006-06-09T11:43:18Z")

</div>

Perfect 🙂

thanks

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 12, 2006, 11:20am UTC](https://www.ruby-forum.com/t/acts-as-drop-down/94318/5 "2006-06-12T11:20:35Z")

</div>

Just a quick clarification:

1. This method would go into the model that accesses the forname and  
surname, right?
2. and the acts\_as\_drop\_down would go into the rhtml file that renders  
the drop down list?

Sorry it’s a bit of a newbie question, but I’m going to try to use  
this… and I’m just a bit confused.  
thanks  
Mohit.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 9, 2006, 11:56am UTC](https://www.ruby-forum.com/t/acts-as-drop-down/94318/6 "2006-06-09T11:56:13Z")

</div>

Hi

Is there any way for a sortable\_element to execute javascript on  
success? I  
have a sortable list of editable objects, and whenever they are moved  
they  
call the ‘update\_positions’ function to store the new position  
information.  
More than one user can update a report at the same time, and in  
‘update\_positions’ there is a check to see if the report has been  
altered by  
another user since this user started editing it. Basically i want to  
refresh  
the page if the data is old, but return nothing if the data is current.  
I’ve  
tried using :success, :complete etc in the sortable\_element call but  
none of  
them seem to work. The only thing that seems to work is :update, but  
it’s  
not much use to me because i want to execute returned javascript, not  
update  
the whole page when most of the time there is no need to. Am I just  
using  
:success wrongly, or is it not supported for sortable\_elements?

In my view:

\<%= sortable\_element(‘sortable\_items’,  
:tag =\> ‘div’,  
:constraint =\> false,  
#:success =\> doesn’t work?  
#:complete =\> doesn’t work?  
#:update =\> works but i don’t want to update every time  
:url =\> {:controller =\> ‘report’, :action =\>  
:update\_positions}) %\>

In my controller:

```
#--------------------------------------------------------------------------

```

* * *

```
# update_positions()
# Save the positions of the report components when they are re-ordered
def update_positions
	# Security check
	unauthorised_action ParamsNotProvidedError unless params
	unauthorised_action InsufficientPrivilegesError unless

```

@session[:navigation][:current\_report].is\_writable?(@session[:user])  
return false if self.auth\_err

```
	if @session[:navigation][:current_report].has_been_modified?
		force_reload
		return false
	end

	params[:sortable_items].each_index do |i|
		item = ReportComponent.find(params[:sortable_items][i])
		item.position = i
		item.save
	end

	render :nothing => true
end

private
#--------------------------------------------------------------------------

```

* * *

```
# force_reload()
def force_reload
	render :text => "alert('data has changed blah

```

blah’);window.document.href=’" +  
url\_for(:controller =\> ‘report’,  
:action =\> ‘report\_builder’,  
:id =\> @session[:navigation][:current\_report].id) + “’;”  
end

thanks  
stan

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 12, 2006, 7:04pm UTC](https://www.ruby-forum.com/t/acts-as-drop-down/94318/7 "2006-06-12T19:04:48Z")

</div>

Daniel N wrote:

> def full\_name  
> “#{self.forename}, #{self.surname}”  
> end
> 
> …  
> end

Hi Daniel,

Thanks for the quick reply! Appreciate it 🙂  
Cheers  
Mohit

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 12, 2006, 12:04pm UTC](https://www.ruby-forum.com/t/acts-as-drop-down/94318/8 "2006-06-12T12:04:48Z")

</div>

On 6/12/06, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Just a quick clarification:
> 
> 1. This method would go into the model that accesses the forname and  
> surname, right?
> 2. and the acts\_as\_drop\_down would go into the rhtml file that renders  
> the drop down list?

I haven’t used this much, just played with it but I believe that you are  
correct for point 1.

The acts\_as\_drop\_down statement belongs in your model class decleration

class MyModel \< ActiveRecord::Base  
acts\_as\_drop\_down :text =\> :full\_name, :order =\> :forename, :value =\>  
:id

def full\_name  
“#{self.forename}, #{self.surname}”  
end

…  
end

Sorry it’s a bit of a newbie question, but I’m going to try to use

> this… and I’m just a bit confused.  
> thanks  
> Mohit.

I hope it’s right, because I’m a bit of a Newbie myself 😉
