Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

PopeOnABomb's Profile

GitHub User: PopeOnABomb

Comments by

Avatar

I'm combining this with dynamic forms from episode #403. The jQuery doesn't fire for the properties when looping through the following lines...

edit.html.erb
<%= f.fields_for :properties do |builder| %>
  <% @product.product_type.fields.each do |field| %>
    <%= render "products/fields/#{field.field_type}", field: field, f: builder %>
  <% end %>
<% end %>

The datepicker works perfectly for anything being edited that isn't within properties. Troubleshooting it seems that the issue is jQuery being called/attached/whatever-term-you-want before the builder finishes. If I add the following lines, the name will trigger its changes, but the date will not.

products.js.coffee
# For the sake of testing, I've hard-wired the id names in to eliminate passing the id names as being the problem.
jQuery ->
$("#hardware_model_name").change ->
alert "name has been changed"

jQuery ->
 $("#hardware_model_properties_test_date").change ->
   alert "date has been changed"

How does one properly include the jQuery for render calls?

Avatar

Alright, I figured out the 406 problem for other people who run in to it.

This is not a server-side issue, but rather an error in a presumption made in this example.

Odds are you're implementing this for a controller that already exists, and it already has a "def index" section.

For example, my code already had this:

# GET /users
# GET /users.xml
def index
 @users = User.all

 respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @users }
end

The 406 is occurring because this def index doesn't have a way to respond to javascript requests.

So after the format.xml line, add this:

format.js { @categories = Category.find(:all, :conditions => ['name like ?', "%#{params[:search]}%"]) }

VIOLA!

Avatar

Several other users have mentioned it, and there has been no resolution posted.

When I go to http://localhost/categories.js, as shown in the demo, nothing is listed and a 406 error is returned in the logs.

Can someone provide a solution for this?