The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

tylere (6) [Avatar] Offline
#1
I can't seem to get the add another file link to work correctly.

Or, rather, it DOES work, but it also generates a request to ticket/:id/new so each click of the button generates an entirely new form "within" the existing form.

Sample console output:

Started GET "/files/new?number=3" for 127.0.0.1 at 2012-01-11 16:06:34 -0500
Processing by FilesController#new as */*
Parameters: {"number"=>"3"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
Rendered files/_form.html.haml (26.3ms)
Completed 200 OK in 35ms (Views: 29.4ms | ActiveRecord: 3.2ms)


Started GET "/projects/3/tickets/new" for 127.0.0.1 at 2012-01-11 16:06:34 -0500
Processing by TicketsController#new as */*
Parameters: {"project_id"=>"3"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
Project Load (0.3ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT 1 [["id", "3"]]
Rendered files/_form.html.haml (1.2ms)
Rendered tickets/_form.html.haml (4.8ms)
Rendered tickets/new.html.haml within layouts/application (6.4ms)
Completed 200 OK in 25ms (Views: 15.5ms | ActiveRecord: 5.3ms)
tylere (6) [Avatar] Offline
#2
Re: Chapter 9.4.5
To add more info, here is the HTML from the page:



<!DOCTYPE html>
<html>
<head>
<title>
Ticketee
</title>
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/admin/permissions.js?body=1" type="text/javascript"></script>
<script src="/assets/admin/users.js?body=1" type="text/javascript"></script>
<script src="/assets/files.js?body=1" type="text/javascript"></script>
<script src="/assets/projects.js?body=1" type="text/javascript"></script>
<script src="/assets/tickets.js?body=1" type="text/javascript"></script>
<script src="/assets/users.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="wZ1WC1ffb4pwUVBSdo42w2aXNAfOwGQimWnRFTwHK2Q=" name="csrf-token" />
</head>
<body>
<h1>Ticketee</h1>
<nav>
Signed in as tylere@gmail.com
Sign out


Admin

</nav>
<h2>New Ticket</h2>
<form accept-charset="UTF-8" action="/projects/9/tickets" class="new_ticket" enctype="multipart/form-data" id="new_ticket" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="wZ1WC1ffb4pwUVBSdo42w2aXNAfOwGQimWnRFTwHK2Q=" /></div>


<label for="ticket_title">Title</label>

<input id="ticket_title" name="ticket[title]" size="30" type="text" />



<label for="ticket_description">Description</label>

<textarea cols="40" id="ticket_description" name="ticket[description]" rows="20"></textarea>


<div id='files'>


<label for="ticket_assets_attributes_0_asset">File #1</label>
<input id="ticket_assets_attributes_0_asset" name="ticket[assets_attributes][0][asset]" type="file" />




<label for="ticket_assets_attributes_0_asset">File #2</label>
<input id="ticket_assets_attributes_0_asset" name="ticket[assets_attributes][0][asset]" type="file" />




<label for="ticket_assets_attributes_0_asset">File #3</label>
<input id="ticket_assets_attributes_0_asset" name="ticket[assets_attributes][0][asset]" type="file" />


</div>
Add another file
<input name="commit" type="submit" value="Create Ticket" />
</form>
</body>
</html>

and here is tickets.js.coffee

$(->
$('a#add_another_file').click(->
url = "/files/new?number=" + $('#files input').length
$.get(url,
(data)->
$('#files').append(data)
)
)
)
ryanbigg (423) [Avatar] Offline
#3
Re: Chapter 9.4.5
Hi Tyler,

Could you please put this application on GitHub so I can see it?

Thanks!
tylere (6) [Avatar] Offline
#4
Re: Chapter 9.4.5
tylere (6) [Avatar] Offline
#5
Re: Chapter 9.4.5
Seems like it has something to do with the link target.

I changed the link to a span with the add_another_file id and edited the cs accordingly and it works fine.
tylere (6) [Avatar] Offline
#6
Re: Chapter 9.4.5
Ok, I figured out what was was going on.

Somehow I had like a coruppted cache of application.js, so all of the js was getting sent twice, and the old version of tickets.js wasn't calling the right url.
ryanbigg (423) [Avatar] Offline
#7
Re: Chapter 9.4.5
This could have happened if you did not clear the public/assets directory (by using rake assets:clean) before running assets:precompile.