<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: floraheathcote</title>
    <description>The latest articles on DEV Community by floraheathcote (@floraheathcote).</description>
    <link>https://dev.to/floraheathcote</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F734434%2F932231ce-8b2e-4c71-8c8e-5175fed306a4.png</url>
      <title>DEV Community: floraheathcote</title>
      <link>https://dev.to/floraheathcote</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/floraheathcote"/>
    <language>en</language>
    <item>
      <title>Turbostreams not working after addition of stimulus in HTML</title>
      <dc:creator>floraheathcote</dc:creator>
      <pubDate>Sat, 23 Oct 2021 17:09:38 +0000</pubDate>
      <link>https://dev.to/floraheathcote/turbostreams-not-working-after-addition-of-stimulus-in-html-4mln</link>
      <guid>https://dev.to/floraheathcote/turbostreams-not-working-after-addition-of-stimulus-in-html-4mln</guid>
      <description>&lt;p&gt;I'm a newbie and this is my first post so apologies if anything is unclear - your help is hugely appreciated!&lt;/p&gt;

&lt;p&gt;I'm working on a non-commercial site just to learn some Rails &amp;amp; Hotwire basics. Here's the recently uploaded Heroku live site if you're curious: &lt;a href="https://www.fodderlist.com/"&gt;fodderlist.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/floraheathcote/fodderlist"&gt;Git repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have a Meal Plan page, which contains many Days, each with many Meals, each with many Meal Recipes.&lt;/p&gt;

&lt;p&gt;Previously, I had the code below (without any Stimulus), which worked perfectly with turbostreams, with each bit rendering when I made changes without reloading the whole page.&lt;/p&gt;

&lt;p&gt;Then... I added a Stimulus controller to show/hide the Meal Recipe (code bottom of page). The Stimulus Show/Hide bits work perfectly but just that one change means that now when I add a new MealRecipe or change portion quantities, the whole page is loaded and not just the turbo frame. Adding the divs for the Stimulus has broken turbolinks functionality. &lt;strong&gt;Why is this ?!! Please help!&lt;/strong&gt; Thanks in advance.&lt;/p&gt;

&lt;h5&gt;
  
  
  _meal_recipe.html.erb (before Stimulus added)
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= turbo_frame_tag("meal_recipe#{meal_recipe.id}") do %&amp;gt;

    &amp;lt;div class="row"&amp;gt;
        &amp;lt;div class="col-1"&amp;gt;
            &amp;lt;%= image_tag(meal_recipe.recipe.main_image, class: "rounded-circle", size: '60', style: 'object-fit: cover')  %&amp;gt; 
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="col-4"&amp;gt;
            &amp;lt;h6&amp;gt;&amp;lt;%= meal_recipe.recipe.name %&amp;gt;&amp;lt;/h6&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;% if meal_plan.status=="draft" %&amp;gt;
        &amp;lt;%= render "meal_recipe_portion_info", leftover: leftover, meal_recipe: meal_recipe %&amp;gt;
    &amp;lt;% else %&amp;gt;
        &amp;lt;span class="badge bg-light text-dark"&amp;gt;
            &amp;lt;%= pluralize(round_nicely(meal_recipe.portions), "portion") -%&amp;gt;
        &amp;lt;/span&amp;gt;
    &amp;lt;% end %&amp;gt;

    &amp;lt;%= turbo_stream_from("meal_recipe_ingredients_list#{meal_recipe.id}") %&amp;gt;
    &amp;lt;%= turbo_frame_tag("meal_recipe_ingredients_list#{meal_recipe.id}") do %&amp;gt;


                &amp;lt;small class="text-muted"&amp;gt;&amp;lt;br&amp;gt;
                        &amp;lt;% meal_recipe.meal_ingredients.includes(:ingredient).each do |meal_ingredient| %&amp;gt;
                            &amp;lt;%= render 'meal_ingredients/meal_ingredient', meal_ingredient: meal_ingredient, meal_plan: @meal_plan %&amp;gt;
                        &amp;lt;% end %&amp;gt;
                &amp;lt;/small&amp;gt;

                &amp;lt;small&amp;gt; Add ingredient to this recipe: &amp;lt;/small&amp;gt;
                &amp;lt;%= turbo_frame_tag "meal_ingredient_form_mealrecipe#{meal_recipe.id}" do %&amp;gt;
                    &amp;lt;%= render 'meal_ingredients/form',  url: meal_recipe_meal_ingredients_path(meal_recipe), meal_ingredient: @meal_ingredient, method: :post, id: "mealrecipe#{meal_recipe.id}mealingredient#{@meal_ingredient.id}" %&amp;gt;
                &amp;lt;% end %&amp;gt;&amp;lt;br&amp;gt;

        &amp;lt;/div&amp;gt;
    &amp;lt;% end %&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  _meal_recipe.html.erb (after Stimulus added)
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= turbo_frame_tag("meal_recipe#{meal_recipe.id}") do %&amp;gt;

    &amp;lt;div class="row"&amp;gt;
        &amp;lt;div class="col-1"&amp;gt;
            &amp;lt;%= image_tag(meal_recipe.recipe.main_image, class: "rounded-circle", size: '60', style: 'object-fit: cover')  %&amp;gt; 
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="col-4"&amp;gt;
            &amp;lt;h6&amp;gt;&amp;lt;%= meal_recipe.recipe.name %&amp;gt;&amp;lt;/h6&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;% if meal_plan.status=="draft" %&amp;gt;
        &amp;lt;%= render "meal_recipe_portion_info", leftover: leftover, meal_recipe: meal_recipe %&amp;gt;
    &amp;lt;% else %&amp;gt;
        &amp;lt;span class="badge bg-light text-dark"&amp;gt;
            &amp;lt;%= pluralize(round_nicely(meal_recipe.portions), "portion") -%&amp;gt;
        &amp;lt;/span&amp;gt;
    &amp;lt;% end %&amp;gt;

    &amp;lt;%= turbo_stream_from("meal_recipe_ingredients_list#{meal_recipe.id}") %&amp;gt;
    &amp;lt;%= turbo_frame_tag("meal_recipe_ingredients_list#{meal_recipe.id}") do %&amp;gt;

        &amp;lt;div data-controller="toggle" data-toggle-visible-value="show" 
                                    data-toggle-hide-text="Hide ingredients" 
                                    data-toggle-show-text="Show/add ingredients"
                                    data-toggle-hide-on-load-value=true&amp;gt;&amp;lt;br&amp;gt;

            &amp;lt;button type="button" class="btn btn-primary " 
                data-action="click-&amp;gt;toggle#showhide"
                data-toggle-target="buttonText"&amp;gt;
                Show/add ingredients
            &amp;lt;/button&amp;gt;&amp;lt;br&amp;gt;

            &amp;lt;div data-toggle-target="content"&amp;gt;
                &amp;lt;small class="text-muted"&amp;gt;&amp;lt;br&amp;gt;
                        &amp;lt;% meal_recipe.meal_ingredients.includes(:ingredient).each do |meal_ingredient| %&amp;gt;
                            &amp;lt;%= render 'meal_ingredients/meal_ingredient', meal_ingredient: meal_ingredient, meal_plan: @meal_plan %&amp;gt;
                        &amp;lt;% end %&amp;gt;
                &amp;lt;/small&amp;gt;

                &amp;lt;small&amp;gt; Add ingredient to this recipe: &amp;lt;/small&amp;gt;
                &amp;lt;%= turbo_frame_tag "meal_ingredient_form_mealrecipe#{meal_recipe.id}" do %&amp;gt;
                    &amp;lt;%= render 'meal_ingredients/form',  url: meal_recipe_meal_ingredients_path(meal_recipe), meal_ingredient: @meal_ingredient, method: :post, id: "mealrecipe#{meal_recipe.id}mealingredient#{@meal_ingredient.id}" %&amp;gt;
                &amp;lt;% end %&amp;gt;&amp;lt;br&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;% end %&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
