Reputation: 4127
Following the instructions here:
http://rubydoc.info/gems/select2-rails/3.1.0/frames
I still cannot get the select2 displays to show in my simple Rails app. I've made sure the gem installed, added //= require select2
to application.js
, and added *= require select2
to application.css
. Further, I've included the following in a users.js.coffee
:
jQuery ->
$('#user_position_ids').select2
I have a User model that has many Positions:
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation,
:first_name, :last_name, :position_ids
has_many :positions
has_one :current_position, :class_name => "Position",
:conditions => { :is_current => true }
end
I am trying to get the select2 to show on a collection_select
on my users/index.html.erb
page:
<%= form_for(@user) do |f| %>
<%= f.collection_select(:position_ids, Position.order(:industry), :id,
:industry, {include_blank:true}, {multiple:true}) %>
<% end %>
Hence the $('#user_position_ids').select2
line in my javascripts. Just can't get select2 to display for some reason so would really appreciate someone pointing me in the right direction. Thanks!
Upvotes: 0
Views: 1281
Reputation: 205
I ran the same issue. After adding the brackets to my coffeescript it worked properly.
So, in your case:
user.js.coffee:
jQuery ->
$('#user_position_ids').select2()
or with some options:
jQuery ->
$('#user_position_ids').select2({
placeholder: "Tags...",
width: "element",
})
Upvotes: 1