Note that there are some explanatory texts on larger screens.

plurals
  1. POCoffeescript with "#{}" makes rails so slow
    primarykey
    data
    text
    <p>My friend and I were coding a partial to be called in a view:</p> <p>When user clicks on any button, a menu is shown, and after selecting something, he will be redirected to another page. That page is decided by the product number, something along the product/:id.</p> <p>but when we used <code>"product/#{product.id}"</code> coffeescript of in our partial, The site became so slow, more than 7s to load it, but when we saved the product.id on a hidden text, it was loaded in less than 0.5s. </p> <p>And the only change was this! except <code>"product/#{product.id}"</code> -> <code>"product/" + ${#sth}.val()</code></p> <p>Is there any reason for this? </p> <p>-- Update: This is the code I've used, I know it's so messy right now, cause we changed it a lot: But that's the idea</p> <pre><code>- if product.blank? - id = "new" - path = "#{new_software_path}/" - else - id = product.id - path = product.getFileLink(:DASHBOARD_LINK) .modal.hide.fade{:id =&gt; "role-options-#{id}","aria-hidden" =&gt; "true", "aria-labelledby" =&gt; "myModalLabel", :role =&gt; "dialog", :tabindex =&gt; "-1"} .modal-header %button.close{"aria-hidden" =&gt; "true", "data-dismiss" =&gt; "modal", :type =&gt; "button"} × %h3#myModalLabel choose a language .modal-body.profile_body %input{type: :hidden, class: id, value: path} %select{class: id} %option{value: :en} English %option{value: :de} German .modal-footer %button.btn{"aria-hidden" =&gt; "true", "data-dismiss" =&gt; "modal"}= t("forms.close") %button.btn.btn-primary{"data-id" =&gt; id}= t("forms.submit") :coffeescript $(".btn-primary").click -&gt; $id = "." + $(this).data("id") window.location.href = $("input." + $id).val() + $("select." + $id).val() alert(#{product.id}); </code></pre> <hr> <p>My rails log shows: </p> <p>With 'alert' part:</p> <pre><code>Started GET "/dashboard/softwares" for 127.0.0.1 Processing by SoftwaresController#manage as HTML Rendered shared/_otherlanguage.html.haml (141.5ms) Rendered shared/_otherlanguage.html.haml (150.0ms) Rendered shared/_otherlanguage.html.haml (149.3ms) ... Rendered shared/_otherlanguage.html.haml (139.8ms) Rendered softwares/manage.html.haml within layouts/dashboard (12869.5ms) Rendered layouts/_dashboard_navigation.html.haml (2.4ms) Completed 200 OK in 12922ms (Views: 12890.0ms) </code></pre> <p>Without 'alert' part:</p> <pre><code>Started GET "/dashboard/softwares" for 127.0.0.1 at 2013-07-02 10:09:44 +0430 Rendered shared/_otherlanguage.html.haml (145.6ms) Rendered shared/_otherlanguage.html.haml (3.8ms) Rendered shared/_otherlanguage.html.haml (0.9ms) Rendered shared/_otherlanguage.html.haml (0.8ms) ... Rendered shared/_otherlanguage.html.haml (0.8ms) Rendered softwares/manage.html.haml within layouts/dashboard (477.9ms) Rendered layouts/_dashboard_navigation.html.haml (0.9ms) Completed 200 OK in 577ms (Views: 549.6ms) </code></pre> <hr> <p>As I said, we created a partial that would get a 'product' object for locals, and used it to generate the link, when clicking submit.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload