Today, I would like to show how you my integeate recordselect into activescaffold for rails3.
I will use my players/team example as usual.
My example will show you how to use :record_select instead of :select for team association in players controller.
Let s start by adding recordselect to our application
rails plugin install https://github.com/vhochstein/recordselect.git
Adding recordselect includes to application layout
<%= active_scaffold_includes %> <%= record_select_includes %>
Enabling recordselect in teams_controller
teams_controller.rb
class TeamsController < ApplicationController
record_select :per_page => 3, :search_on => [:name], : order_by => 'name'
...
Adding recordselect routes for teams_controller
routes.rb
resources :teams do
as_routes
record_select_routes
end
Changing form_ui to :record_select for team column
players_controller.rb
active_scaffold :player do |conf|
conf.columns[:team].form_ui = :record_select
...
Restart your application and you should be able to choose a team for a player using record_select.
Jan 28, 2011 @ 03:54:08
Volker,
Just played around with this. This is certainly nice for a lot of associations. I think I might write something similar using the jquery ui to do a search against the model association. That way if you have hundreds of records to select from you could use the autocomplete function. If I do you will be the first to know
Very nice work.
Thanks!
Mark
Jan 28, 2011 @ 08:46:34
Thanks a lot, I have to pass the honour to Lance Irvy, he has written recordselect, I ve just migrated it to rails 3
Jan 28, 2011 @ 04:19:50
Does this work with jquery? I tried it all as you described but nothing appeared when I typed in the box. When I try with prototype, it does work. It could be my setup but before I spend too much more time trying to figure it out, I figured I would ask if it is known that jquery does not work with this.
Jan 28, 2011 @ 08:45:22
Works for me with jquery also, which means we have to figure out why it is nt working for you. Can you please open an issue?
Apr 28, 2011 @ 08:49:04
I have same problem, when i setup Active Scaffold in gemfile. When i try install it as a plugin and configure it (uncomment last line in …plugins/active_scaffold/lib/active_scaffold_env.rb in order to use jquery instead of prototype), record select works fine
Mar 04, 2011 @ 13:29:57
yeah nice
Apr 13, 2011 @ 08:35:40
Saayyyy….
How do I get selection via cursor into this again?
Regards
Michael
Apr 13, 2011 @ 12:52:38
implementation for selection via cursor is quite buggy…..