Forum: Ruby on Rails acts as drop down

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.
Guest (Guest)
on 2006-04-28 19:24
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
scott (Guest)
on 2006-06-09 12:37
still stuck on this one,

I need the select box to show both forename and surname, any
suggestions?
Daniel -. (Guest)
on 2006-06-09 13:25
(Received via mailing list)
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
scott (Guest)
on 2006-06-09 13:43
Perfect :)

thanks
ã?¹ã?¿ã?³ ã??ã?ºã?¬ã??ã?¯ (Guest)
on 2006-06-09 13:56
(Received via mailing list)
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
Mohit S. (Guest)
on 2006-06-12 13:20
(Received via mailing list)
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.
Daniel -. (Guest)
on 2006-06-12 14:04
(Received via mailing list)
On 6/12/06, Mohit S. <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 ;)
Mohit S. (Guest)
on 2006-06-12 21:04
(Received via mailing list)
Daniel N wrote:
>
> def full_name
>   "#{self.forename}, #{self.surname}"
> end
>
> ....
> end

Hi Daniel,

Thanks for the quick reply!  Appreciate it :)
Cheers
Mohit
This topic is locked and can not be replied to.