title: How to add Ruby code in JQuery?
body: <p>I am newbie and limited experience in Ruby with jQuery codes.  </p>
  
  <p>How to add Ruby codes in jQuery?</p>
  
  <p>I have attempted to insert part in jQuery using from _multicourse_meal.html.erb as shown bold below which does not work, except,  not enabling to call delete method from meal_(meal).  How to do it with jQuery?</p>
  
  <pre><code>$('#new-&lt;%= @multicourse_meal.id %&gt;').before("
  &lt;tr id=&lt;%= @meal.id %&gt;&gt;
  &lt;td&gt;**&lt;%= link_to '&lt;i class="icon-remove"&gt;&lt;/i&gt;'.html_safe, meal_path(meal), method: :delete, remote: true %&gt;**(&lt;--ERROR code)&lt;%= meal.title %&gt;
  &lt;/i&gt; &lt;%= @meal.title %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= @meal.portion_amt_g %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= @meal.calories %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= @meal.carbs_amt_g.round(1) %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= @meal.protein_amt_g.round(1) %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= @meal.fat_amt_g.round(1) %&gt;&lt;/td&gt;&lt;/tr&gt;")
  </code></pre>
  
  <p>.</p>
  
  <pre><code>application.html.erb in views/layouts
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;&lt;%= full_title(yield(:title)) %&gt;&lt;/title&gt;
      &lt;%= stylesheet_link_tag    "application", media: "all" %&gt;
      &lt;%= javascript_include_tag :defaults, "application" %&gt;
      &lt;%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/smoothness/jquery-ui.css" %&gt;
      &lt;%= csrf_meta_tags %&gt;
      &lt;%= render 'layouts/shim' %&gt;    
    &lt;/head&gt;
    &lt;body&gt;
      &lt;%= render 'layouts/header' %&gt;
      &lt;div class="container"&gt;
        &lt;% flash.each do |key, value| %&gt;
          &lt;div class="alert alert-&lt;%= key %&gt;"&gt;&lt;%= value %&gt;&lt;/div&gt;
        &lt;% end %&gt;
        &lt;%= yield %&gt;
        &lt;%= render 'layouts/footer' %&gt;
        &lt;%= debug(params) if Rails.env.development? %&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>.</p>
  
  <pre><code>_multicourse_meals.html.erb in views/multicourse_meals
  
  &lt;% @multicourse_meals_for_the_day.each do |multicourse_meal| %&gt;
      &lt;table class="table table-condensed table-striped table-bordered"&gt;
          &lt;thead&gt;     
              &lt;tr&gt;
                  &lt;th&gt;Meal: &lt;%= multicourse_meal.meal_no %&gt;&lt;/th&gt;
                  &lt;th&gt;Portion Size (ml/g.)&lt;/th&gt;
                  &lt;th&gt;Calories&lt;/th&gt;
                  &lt;th&gt;Carbs: (g.)&lt;/th&gt;
            &lt;th&gt;Pro: (g.)&lt;/th&gt;
            &lt;th&gt;Fat: (g.)&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              &lt;% multicourse_meal.meals.each do |meal| %&gt;
                  &lt;tr id="&lt;%= meal.id %&gt;"&gt;
                      &lt;td&gt;
                          &lt;%= link_to '&lt;i class="icon-remove"&gt;&lt;/i&gt;'.html_safe, meal_path(meal), method: :delete, remote: true %&gt;
                          &lt;%= meal.title %&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;%= meal.portion_amt_g %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%= meal.calories %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%= meal.carbs_amt_g.round(1) %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%= meal.protein_amt_g.round(1) %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%= meal.fat_amt_g.round(1) %&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;% end %&gt;
              &lt;tr id="new-&lt;%= multicourse_meal.id %&gt;"&gt;
                  &lt;td&gt;
                      &lt;%= form_for( @meal, remote: true) do |f| %&gt;
                          &lt;%= f.select :nutrient_id, options_for_select(Nutrient.all.collect { |p| [p.title, p.id]}) %&gt;
                          &lt;%= f.text_field :portion_amt_g, class: "input-mini" %&gt;
                          &lt;%= f.hidden_field :multicourse_meal_id, :value =&gt; multicourse_meal.id %&gt;
                          &lt;%= f.submit "Add" %&gt;
                      &lt;% end %&gt;
                  &lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;th&gt;&lt;/th&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;th&gt;Target Amount&lt;/th&gt;
                  &lt;td&gt;&lt;%= multicourse_meal.tgt_calories %&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%= multicourse_meal.tgt_carbs_amt_g.round(1) %&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%= multicourse_meal.tgt_protein_amt_g.round(1) %&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%= multicourse_meal.tgt_fat_amt_g.round(1) %&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;th&gt;Total&lt;/th&gt;
                  &lt;td id="&lt;%= multicourse_meal.id %&gt;-tot_calories"&gt;&lt;%= multicourse_meal.total_calories %&gt;&lt;/td&gt;
                  &lt;td id="&lt;%= multicourse_meal.id %&gt;-tot_carbs"&gt;&lt;%= multicourse_meal.total_carbs_amt_g.round(1) %&gt;&lt;/td&gt;
                  &lt;td id="&lt;%= multicourse_meal.id %&gt;-tot_protein"&gt;&lt;%= multicourse_meal.total_protein_amt_g.round(1) %&gt;&lt;/td&gt;
                  &lt;td id="&lt;%= multicourse_meal.id %&gt;-tot_fat"&gt;&lt;%= multicourse_meal.total_fat_amt_g.round(1) %&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>.</p>
  
  <pre><code>create.js.erb in views/meals
  
  $('#new-&lt;%= @multicourse_meal.id %&gt;').before("&lt;tr id=&lt;%= @meal.id %&gt;&gt;&lt;td&gt;&lt;i class='icon-remove'&gt;&lt;/i&gt; &lt;%= @meal.title %&gt;&lt;/td&gt;&lt;td&gt;&lt;%= @meal.portion_amt_g %&gt;&lt;/td&gt;&lt;td&gt;&lt;%= @meal.calories %&gt;&lt;/td&gt;&lt;td&gt;&lt;%= @meal.carbs_amt_g.round(1) %&gt;&lt;/td&gt;&lt;td&gt;&lt;%= @meal.protein_amt_g.round(1) %&gt;&lt;/td&gt;&lt;td&gt;&lt;%= @meal.fat_amt_g.round(1) %&gt;&lt;/td&gt;&lt;/tr&gt;")
  
      // update multicourse meal view
      $('#&lt;%= @multicourse_meal.id %&gt;-tot_calories').html("&lt;%= @multicourse_meal.total_calories %&gt;")
      $('#&lt;%= @multicourse_meal.id %&gt;-tot_carbs').html("&lt;%= @multicourse_meal.total_carbs_amt_g.round(1) %&gt;")
      $('#&lt;%= @multicourse_meal.id %&gt;-tot_protein').html("&lt;%= @multicourse_meal.total_protein_amt_g.round(1) %&gt;")
      $('#&lt;%= @multicourse_meal.id %&gt;-tot_fat').html("&lt;%= @multicourse_meal.total_fat_amt_g.round(1) %&gt;")
  
      // update calories Journal view
      $('#meals_mn_ratio').html("&lt;%= @calories_journal.meals_mn_ratio %&gt;");
      $('#cj_total_calories').html("&lt;%= @calories_journal.total_calories %&gt;");
      $('#cj_total_carbs').html("&lt;%= @calories_journal.total_carbs_amt_g.round(1) %&gt;");
      $('#cj_total_pro').html("&lt;%= @calories_journal.total_protein_amt_g.round(1) %&gt;");
      $('#cj_total_fat').html("&lt;%= @calories_journal.total_fat_amt_g.round(1) %&gt;");
  </code></pre>