LondonGuy
LondonGuy

Reputation: 11098

How to delete record by the click of a link in ruby on rails?

What's the best way to delete something a table in my database by the click of a link? I have a birthday date drop and when a user selects their birthday and clicks update the db is updated with their D.O.B. and the fields disappear and are replaced with the persons birthday in text format e.g. January, 1 2012.

I'd like to have a link next to this called "change" and when the user clicks change the database value is set to NULL meaning the dropdown fields will appear again, allowing them to select their birthday.

Also how do I have ruby on rails only perform validation on a new record that hasn't been created? and not perform validation if data already exists?

Any ideas? Kind regards

Upvotes: 0

Views: 150

Answers (1)

tadman
tadman

Reputation: 211560

For something like that you might just want to have a JavaScript toggle to show the date picker when required, or just show "Change" otherwise. Of course for any record that new_record? is true, you'd want to show it by default.

As for the validation part, just add :on => :create to the options for it and it should only trigger for new records.

Upvotes: 1

Related Questions