scambra / recordselect Goto Github PK
View Code? Open in Web Editor NEWThis project forked from cainlevy/recordselect
Replaces <select> tags with a full-HTML, RESTful JavaScript record browser (Rails plugin)
License: MIT License
This project forked from cainlevy/recordselect
Replaces <select> tags with a full-HTML, RESTful JavaScript record browser (Rails plugin)
License: MIT License
RecordSelect ============ (c) 2007 - 2016 Sergio Cambra, Lance Ivy RecordSelect is a Rails widget to help you pick one record out of many. I designed it as a more usable and performant alternative to generating a massive dropdown list. It relies on AJAX, powered by jQuery, so jQuery must be loaded first, either from jquery-rails gem or just loading the JS in the assets pipeline, or imported before importing record_select if using importmap. Please see the ActionView::Helpers::RecordSelectHelpers for the most common API. More documentation (and HOWTOs) can be found online at the wiki. = USAGE WITH ASSETS PIPELINE Add to application.js ```js //= require jquery //= require record_select ``` = USAGE WITH IMPORTMAP Add to importmap.rb ```rb pin "jquery" pin "record_select" ``` Add to app/assets/config/manifest.js ```js //= link jquery.js //= link record_select.js ``` Add to app/javascript/application.js ```js import 'jquery' import 'record_select' ``` = USAGE WITH ACTIVE_SCAFFOLD Either using assets pipeline or importmap, it will be loaded when requiring or importing active_scaffold, so no need to add it to application.js, importmap.rb or manifest.js = DEPENDENCIES This depends on the excellent Paginator gem by Bruce Williams. This simple gem is available at paginator.rubyforge.org. It should autoselect js framework, but you can select :jquery or :prototype framework with config/initializer file: RecordSelect::Config.js_framework = :jquery RecordSelect::Config.js_framework = :prototype
I've installed Active Scaffold and Record Select in a rails 4 app with a relation field form ui set up for recordselect.
I'm getting 500 error when setting cursor to recordselect field. It try to search for records and everything fails in my model to_s
method with error:
Started GET "/faculties/browse?escape=false" for 127.0.0.1 at 2013-08-09 23:49:03 +1000
Processing by FacultiesController#browse as */*
Parameters: {"escape"=>"false"}
User Load (3.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
(1.8ms) SELECT COUNT(*) FROM "faculties"
Rendered /home/envek/.rvm/gems/ruby-2.0.0-p247/gems/recordselect-3.2.11/app/views/record_select/_search.html.erb (11.8ms)
DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published: true).to_a`). (called from call at /home/envek/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active_scaffold-c328fad540d2/lib/active_scaffold/paginator.rb:66)
unknown OID: ?column?(705) (SELECT NULL FROM "faculties" ORDER BY "faculties".name ASC, "faculties".id ASC LIMIT 10 OFFSET 0)
Faculty Load (2.5ms) SELECT NULL FROM "faculties" ORDER BY "faculties".name ASC, "faculties".id ASC LIMIT 10 OFFSET 0
Rendered /home/envek/.rvm/gems/ruby-2.0.0-p247/gems/recordselect-3.2.11/app/views/record_select/_list.html.erb (37.6ms)
Rendered /home/envek/.rvm/gems/ruby-2.0.0-p247/gems/recordselect-3.2.11/app/views/record_select/_browse.html.erb (72.1ms)
Completed 500 Internal Server Error in 143ms
ActionView::Template::Error (missing attribute: name):
18: <% end -%>
19: <% page.items.each do |record| -%>
20: <li class="record <%= cycle 'odd', 'even' %>" id="rs<%= record.id -%>">
21: <%= render_record_in_list(record, controller) %>
22: </li>
23: <% end -%>
24: <% if page.next? -%>
app/models/faculty.rb:12:in `to_s'
Rendered /home/envek/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (11.2ms)
Rendered /home/envek/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (7.7ms)
Rendered /home/envek/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (92.8ms)
My model to_s method is straightforward simple:
def to_s
self.name
end
Firebug console shows record_select.js being loaded twice. The second load is 0 size. I don't know much about JavaScript, but my guess is the second load overwrites the first removing the necessary JavaScript. The end result is missing templates:
19:41:28 web.1 | Completed 500 Internal Server Error in 38ms
19:41:28 web.1 |
19:41:28 web.1 | ActionView::MissingTemplate (Missing template record_select/browse with {:handlers=>[:erb, :builder, :coffee], :formats=>[:js, :html], :locale=>[:en, :en]}. Searched in:
19:41:28 web.1 | * "/Users/jeff/rails/reconn/app/views"
19:41:28 web.1 | * "/Users/jeff/.rvm/gems/ruby-1.9.2-p136@active_scaffold/gems/recordselect-3.1.1/app/views"
19:41:28 web.1 | * "/Users/jeff/.rvm/gems/ruby-1.9.2-p136@active_scaffold/gems/devise-1.4.9/app/views"
19:41:28 web.1 | * "/Users/jeff/.rvm/gems/ruby-1.9.2-p136@active_scaffold/bundler/gems/active_scaffold-d22b3ac72a78/frontends/default/views"
19:41:28 web.1 | ):
19:41:28 web.1 |
19:41:28 web.1 |
19:41:28 web.1 | Rendered /Users/jeff/.rvm/gems/ruby-1.9.2-p136@active_scaffold/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.7ms)
Hello, I just upgraded a Rails 2.3.x site to a Rails 3.2.x site. I had active_scaffold and record_select working previously but after the upgrade I can't seem to get RS to work.
In my Gemfile:
gem 'active_scaffold', git: "https://github.com/activescaffold/active_scaffold.git"
gem "recordselect", git: 'git://github.com/scambra/recordselect.git'
gem 'jquery-rails', '~> 2.1.4' # the latest jquery lib includes jquery 1.9 which removes many deprecations which breaks AS and RS
In my UserController:
record_select :search_on => [:email], :label => Proc.new { |record| record.email }
In the LicenseController active_scaffold config:
config.columns[:user].form_ui = :record_select
and in my routes.rb:
resources :users do
as_routes
record_select_routes
end
resources :licenses do
as_routes
end
When I try to create a new license and search for a user by email, I see this error in the js console:
record_select.js:222 TypeError: 'undefined' is not an object (evaluating '$.rails.fire')
Plainly bundling recordselect in Gemfile leads to
ancalagon:recordselect-3.2.5 michaelp$ ls -lrt
total 24
drwxr-xr-x 3 michaelp staff 102 30 Jan 11:06 test
-rw-r--r-- 1 michaelp staff 935 30 Jan 11:06 README
-rw-r--r-- 1 michaelp staff 1053 30 Jan 11:06 MIT-LICENSE
-rw-r--r-- 1 michaelp staff 1404 30 Jan 11:06 CHANGELOG
ancalagon:recordselect-3.2.5 michaelp$
You have to add the git-reference to your repo aka gem "recordselect" , :git => "https://github.com/scambra/recordselect.git"
to get the real thing:
ancalagon:recordselect-e7899cffd789 michaelp$ ls -l
total 72
-rw-r--r-- 1 michaelp staff 1404 30 Jan 16:02 CHANGELOG
-rw-r--r-- 1 michaelp staff 342 30 Jan 16:02 Gemfile
-rw-r--r-- 1 michaelp staff 1053 30 Jan 16:02 MIT-LICENSE
-rw-r--r-- 1 michaelp staff 935 30 Jan 16:02 README
-rw-r--r-- 1 michaelp staff 825 30 Jan 16:02 Rakefile
drwxr-xr-x 4 michaelp staff 136 30 Jan 16:02 app
drwxr-xr-x 3 michaelp staff 102 30 Jan 16:02 config
-rw-r--r-- 1 michaelp staff 51 30 Jan 16:02 init.rb
-rw-r--r-- 1 michaelp staff 25 30 Jan 16:02 install.rb
drwxr-xr-x 5 michaelp staff 170 30 Jan 16:02 lib
-rw-r--r-- 1 michaelp staff 1223 30 Jan 16:02 recordselect.gemspec
drwxr-xr-x 3 michaelp staff 102 30 Jan 16:02 test
-rw-r--r-- 1 michaelp staff 169 30 Jan 16:02 uninstall.rb
ancalagon:recordselect-e7899cffd789
The jquery version does not seem to be working correctly. The hidden field in the record select container is getting the appropriate text, but the form does not submit on keyup. If I alter the css to show the hidden text field and button and click the submit button manually, then the browse method runs and filters the record_select list.
Hi, the translation files seem broken on Ruby-1.9.3-mingw32.
This seems to be because of the interpolation symbols/strings %{...} you need to use double quotes surrounding the string, when the string starts with an interpolation, etc.
Issues are in both the EN and ES translation.
I get the following error in Rails 5:
gems/recordselect-3.5.0/app/views/record_select/_browse.html.erb
ActionView::Template::Error (Attempting to generate a URL from non-sanitized request parameters! An attacker can inject malicious data into the generated URL, such as changing the host. Whitelist and sanitize passed parameters to be secure.):
1: <% url_options = params.merge(:controller => controller, :action => :browse, :page => 1, :update => 1) -%>
2: <%= form_tag url_options, {:method => :get, :remote => true, :id => record_select_search_id} -%>
3: <%= text_field_tag 'search', params[:search], :autocomplete => 'off', :class => 'text-input' %>
4: <%= submit_tag 'search', :class => "search_submit" %>
5:
given the following:
AccountGroup has_many :accounts
Account belongs_to :account_group
When we render the accounts association in the account group scaffold using the :select
form_ui, the list of available choices includes the currently associated records and any records that are not associated to some other AccountGroup record.
When changing to :record_select
however, the browse action does not have any sense of what scaffold or record is calling the action, and thus no ability to filter the available options based on this.
I have played around with different ways to solve this, such as using record_select_conditions_from_controller to build the conditions, but I noticed another issue, which is that by default there are no other params included in the query besides search
, and if you attempt to add one that will cause it to perform a WHERE account_group_id IS NULL
query, like this:
config.columns[:accounts].options[:params] = { account_group_id: '' }
it does work when you initially click into the search box (scaffolds/accounts/browse?account_group_id=&search=
) -- despite getting an Unpermitted parameter: :account_group_id
warning in the webserver logs -- but once you begin typing some search text, those parameters are no longer sent along with the request (scaffolds/accounts/browse?page=1&search=&update=1&search=asdf
).
Is there some alternate approach that could be taken here to get the list of record_select options to be filtered similarly to the behavior in the :select form_ui?
Thanks!
I get routing error selecting a record in a belongs_to relation with record select.
I have a Player wich belongs to a team and i have configured team with record select. The form record select ui browse correctly all Teams, but when select a Team, i get a routing error /staff/teams/1/select.
I use AS branch rails 3.0 and this record_select fork.
Using git://github.com/vhochstein/recordselect and git://github.com/vhochstein/active_scaffold all works (the vho version of AS not use a record _select helper with a bridge).
I'm using rails 4.2.3 with active_scaffold 3.4.23 and recordselect 3.4.6
On my controller, I used
config.columns[:course].form_ui = :record_select
config.columns[:course].options[:params] = {available: true}
When I click on the record select, it throws the exception:
Started GET "/courses/browse?available=true&search=" for 127.0.0.1 at 2015-07-28 21:58:21 -0300
Processing by CoursesController#browse as */*
Parameters: {"available"=>"true", "search"=>""}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Completed 500 Internal Server Error in 16ms (ActiveRecord: 0.2ms)
NoMethodError - undefined method `type_cast' for #<ActiveRecord::ConnectionAdapters::Column:0x007f5a649b25b0>:
recordselect (3.4.6) lib/record_select/conditions.rb:82:in `record_select_condition_for_column'
recordselect (3.4.6) lib/record_select/conditions.rb:67:in `block in record_select_conditions_from_params'
actionpack (4.2.3) lib/action_controller/metal/strong_parameters.rb:185:in `each_pair'
recordselect (3.4.6) lib/record_select/conditions.rb:63:in `record_select_conditions_from_params'
recordselect (3.4.6) lib/record_select/conditions.rb:14:in `record_select_conditions'
recordselect (3.4.6) lib/record_select/actions.rb:6:in `browse'
actionpack (4.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
...
I think that the method type_cast in line https://github.com/scambra/recordselect/blob/master/lib/record_select/conditions.rb#L82 should be type_cast_from_user on rails 4.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.