Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clean way to make the "confirm" conditional in rails 4

I have a link_to on my rails4 page which uses slim syntax. The following link_to

link_to exports_path, data: { confirm: "Are you sure?" }

is now required to only show the confirm message upon a certain condition. How do we make this happen in rails4?

I tried:

link_to exports_path, data: { confirm: result_count > 50 ? "Are you sure?" : nil }

which seems to always show the confirm regardless of the condition..

like image 232
Swaroop Avatar asked Dec 10 '13 23:12

Swaroop


1 Answers

How about

link_to exports_path, data: (result_count > 50  ?  { confirm:  "Are you sure?"} : nil)
like image 142
DeeY Avatar answered Oct 03 '22 02:10

DeeY