forms - Need help modifying multiple models example from advanced rails recipes book -


I am developing a simple rail app for my own use for learning purposes and I have 2 models in 1 I am trying to handle the form. I have followed the example in Chapter 13 of Advanced Tracks Recipes and have worked with some simple modifications for their own purpose.

I have 2 model invoices and invoice phone numbers. Each invoice can have several invoice phone numbers. What I want to do is ensure that each invoice includes at least 1 phone number. In the example given in the book, I place a 'Remove' link next to each phone number (Work in the book), I want to make sure that it does not have a link near the top-most phone number, but how do I understand it I can do this how to do it. Partial template that produces every line in the list of phone numbers in the invoice, is as follows;

  & lt; Div class = "invoice_phone_number" & gt; & Lt;% new_or_existing = invoice_phone_number.new_record? ? 'New': 'Existing'% & gt; & Lt;% prefix = "Invoice [# {new_or_existing} _invoice_phone_number_attributes] []"%> For the & lt;% fields_ prefix, invoice_phone_number. Invoice_form | -% & gt; & Lt;% = invoice_form.select: phone_type,% w {home work mobile fax}% & gt; & Lt;% = invoice_form.text_field: phone_number% & gt; & Lt;% = link_to_function "Remove", "$ (this) .up ('.invoice_phone_number'). Remove ()"%> & Lt;% end -% & gt; & Lt; / Div & gt; Now, if I came to know that the first phone number is being generated, then I can put a condition on link- link_to_function so that it can not be executed. This half will solve my problem and be satisfactory, though it would mean that if I really want to remove the first phone number and keep the other, then I have to make some manual shuffle.  

The best way to do this is possible with JavaScript in the browser but I do not know how to contact it. I'll need to hide the 'remove' link when there will be only one and all will show 'remove' link when more than one. The functionality used in the .inert_html method does not seem to be enough for this in the 'Add a phone number' link.

How do I not say for a step-by-step (actually I do not want to get one - I want to understand it), but would anyone start with this problem Have any suggestions about?

Thank you.

  & lt;% = render: partial = & gt; ; "Advertisement" ,: collection = & gt; @ Ad% & gt;  

This will provide "Advertiser / _ad.erb" and pass the local variable ad on the template for display. A walk counter will automatically be provided with a name form for the template partial_name_counter. In the case of the above example, the template will be fed to ad_counter .


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -