1

This question is hard to explain so please bear with me. I have a table that contains rows which hold records from the Records table. i can add rows to this table using ajax and when i have entered the hours into a text field on the row and click away, the record gets submitted via ajax. My problem is that i have a delete button next to each row. The rows delete as youd expect when i have refreshed the page or the rows where already in the Records table when the page was loaded. However if i have just added some hours and havent refreshed the page then i cannot delete the record.

After searching ive narrowed it down to this:

Already present record:

<a rel="nofollow" data-method="delete" data-confirm="Are you sure?" href="/records/2">

Just added:

<a class="delete" title="delete row" rel="nofollow" data-remote="true" data-method="delete" data-confirm="Are you sure?" href="Delete">

Because im using the ruby method "delete" from the Records controller it needs a href with the record id, thus "records/2". this wont change until ive refreshed the page which is not what i want.

Ive thought about setting the href of the button when the record gets submitted but i have know idea how to do that in either js or ruby, plus id have to submit and then grab the record id back again. Or if someone can come up with a better idea other than the one above and "refresh the page when it submits" im all ears.

2
  • Why does the new record contain so many more attributes than what is generated by the template? Can you post the code that is generating the row when it's created through the UI? Commented Sep 28, 2011 at 9:22
  • 1
    i think the reason is when i generate it the first time it is adding a row to the table and then when i add hours it will submit a hidden form and write to the datebase. However when i refresh a page my controller looks at the records table and for record it creates a row. its because there two different rows fundamentally. Commented Sep 28, 2011 at 9:28

1 Answer 1

2

Iam guessing you are using rails so what u need to do is the controller should return a js response. check this question. to render erb code in JavaScript you should use escape_javascript.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.