<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sophie Déziel on Medium]]></title>
        <description><![CDATA[Stories by Sophie Déziel on Medium]]></description>
        <link>https://medium.com/@sophiedeziel?source=rss-6d5af0f54123------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CAC16H4xHIoYztoQFAfIZQ.jpeg</url>
            <title>Stories by Sophie Déziel on Medium</title>
            <link>https://medium.com/@sophiedeziel?source=rss-6d5af0f54123------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 13:06:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sophiedeziel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Double Splat Operator]]></title>
            <link>https://medium.com/@sophiedeziel/the-double-splat-operator-83347d924ecf?source=rss-6d5af0f54123------2</link>
            <guid isPermaLink="false">https://medium.com/p/83347d924ecf</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Sophie Déziel]]></dc:creator>
            <pubDate>Wed, 23 Nov 2016 22:25:03 GMT</pubDate>
            <atom:updated>2016-11-23T22:25:03.724Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I read <a href="http://blog.davydovanton.com/2016/11/23/ruby-tips-part-two/">a nice article on Ruby tips</a> by <a href="http://blog.davydovanton.com/">Anton Davydov</a>. I learned about the double splat operator (**) usage in a method definition and shared the tip to my colleagues. We tried several things but we couldn’t find the difference between using it or not. This is what we tried in irb:</p><pre>def without_splat(args, *others, hash_args)<br> hash_args<br>end<br> <br>def with_splat(args, *others, **hash_args)<br> hash_args<br>end<br> <br> with_splat(1, 2, 3, color: “blue”, other: “things”)<br> =&gt; {:color=&gt;”blue”, :other=&gt;”things”}</pre><pre>without_splat(1, 2, 3, color: “blue”, other: “things”)<br> =&gt; {:color=&gt;”blue”, :other=&gt;”things”}</pre><p>Basically, hash_args seems to capture a hash, whether or not the double splat is used or not. This is not very useful… But look at the code bellow:</p><pre>with_splat(1,2,3)<br> =&gt; {}</pre><pre>without_splat(1,2,3)<br> =&gt; 3</pre><p>Ah ha! Without the splat, Ruby assigns the last value to hash_args because it’s the pattern we gave it to follow. The double splat tells Ruby that we expect a hash or named arguments and makes it optional. It acts kinda like hash_args={} in the method signature!</p><p>Now, let’s see if it’s different:</p><pre>def with_default_value(args, *others, hash_args = {})<br>  hash_args<br>end<br>SyntaxError: (irb):1: syntax error, unexpected &#39;=&#39;, expecting &#39;)&#39;<br>def with_default_value(args, *others, hash_args = {})<br>                                                 ^</pre><p>Yes it is!! It allows you to capture an indefinite number of named arguments or a hash right after capturing an array of arguments, which was impossible before that.</p><p>Now, what can we do with it in the real world? Let’s say I want to implement my own version of the <a href="https://github.com/thoughtbot/factory_girl">FactoryGirl gem</a> (let’s call it FactoryBoy). I might use the double splat operator to implement the create method:</p><pre>class FactoryBoy<br>  def self.create(factory_name, *traits, **attributes)<br>    # lots of useful stuff<br>  end<br>end</pre><pre>FactoryBoy.create(:user, :admin, email: &#39;something@cool.com&#39;)</pre><p>I looked at the FactoryGirl source code and it’s actually done in a very different way! But that’s another story…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83347d924ecf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How We Do Spikes]]></title>
            <link>https://medium.com/@sophiedeziel/how-we-do-spikes-4a43f0d19967?source=rss-6d5af0f54123------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a43f0d19967</guid>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[scrum]]></category>
            <category><![CDATA[project-management]]></category>
            <dc:creator><![CDATA[Sophie Déziel]]></dc:creator>
            <pubDate>Fri, 08 Jul 2016 14:12:11 GMT</pubDate>
            <atom:updated>2016-07-08T20:14:07.696Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*-0isN47h1lpfNptH4AZ3_w.jpeg" /></figure><p>A few months ago, we started complaining seriously about the Rails assets pipeline. We did everything we could to bypass some problems, fix others, speed up deployment, compilation or precompile. We had to find an alternative that would work and actually improve the development process. This is not a story about how we decided to replace a Rails component. This is a success story about how we managed uncertainty in an Agile way.</p><p>As the application grows, the challenges or problems are growing too. And it’s not always possible to define stories for a proper scrum, Kanban or any other agile method. If a story can’t be defined precisely, it’s almost impossible to estimate when there is too much uncertainty. As a developer, you don’t want to commit to a 21 points story in a sprint when you don’t even know if it is feasible in the first place. That’s when you do spikes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8DuFwe2U-5yVRE1IqWolg.jpeg" /></figure><p>Our team has a very special agile methodology. We’re improving our process continuously (well, you’re supposed to if you are agile) and we ended up with a mix of Scrum and Kanban. We don’t have artificial deadlines with sprints but we still estimate stories with poker planning. We also love our carefully chosen tools to help us organize, communicate and achieve work without friction. So spikes fit in our process in a very powerful way. But we had to define clearly what is a spike, what is its goal and how to complete it.</p><p>What a spike is is pretty universal. In the image above, “learn about Kanban” and “try Kanban tool” can be considered spikes. Other real-life spikes examples would be:</p><ul><li>Is switching to a CDN worth it?</li><li>Should we convert all our javascripts to coffeescripts?</li><li>We know we will reach the limits of that system soon, what should we do to avoid apocalypse?</li></ul><p>I like to define it as “<em>time dedicated to investigate and document</em>”. Basically, answering those questions will mitigate risks and reduce uncertainty.</p><p>The way they are integrated in our flow is pretty simple. As chores, spikes are not given complexity points. Instead, they get an amount of time. It could be half an hour or two days. It’s what is reasonable to invest in. And it is prioritized as any other story. So a spike can only begin when higher priority stories are done and must be done before lower priority ones. I know, it’s trivial. But still, it’s important to follow those guidelines to avoid losing track of where the team’s resources are spent.</p><p>So, we know how much time to spend on a spike and when, but what will be produced? Since the work done in a spike is about searching, trying and making mistakes, it is very important and valuable to everyone to <strong>document</strong> the progress. When a spike is left there because we ran out of time, we should be able to come back to it and see what has been done in detail. If your project qualifies for a government R&amp;D tax credits program, that documentation will simplify the application and has so much value when verified. Your managers will love it.</p><p>So, the goal of a spike would be to produce knowledge and to reduce uncertainty. So, it’s important to follow some guidelines to make sure that the knowledge is communicated. This can be very useful for every level of development and management. So, here is the questions to be answered (and documented) in the time allocated:</p><ul><li>What is the problem that we want to solve?</li><li>Is it feasible?</li><li>How much effort does it need?</li></ul><p>When the conclusion is that it is possible and the amount of effort is defined, the knowledge produced and documented should be enough for the product owner to create the stories to do the real work and help the development team to estimate it.</p><h3>Documentation guidelines</h3><p>In the case of replacing the Rails assets pipeline, the question was already asked in person and we discussed about it in different situations: before creating the issue, in the poker planning meeting, in the issues related, in informal discussions, etc. To get the big picture, to be able to communicate it, demonstrate its value and what was invested and what will eventually be invested, we have to define clearly what has to be answered. We should start documenting what was done prior to the spike, what are the specific problems and what kind of solution do we value. That approach is “creatively inspired” by some parts of the scientific method.</p><h4>Write a summary of what’s been discussed</h4><p>This is simply to communicate what motivated to get into that spike instead of “just doing X or Z”. X or Y might have unwanted consequences and we have to communicate it. Or maybe the goal of the spike has so much value that X or Y would be a waste of time before we finally try what’s in the spike.</p><h4>Document your steps</h4><p>What’s cool about a spike is that you are autonomous and trusted to make important decisions. Those decisions are important and might have a major impact on the team. For example, if I decide that the best approach is to change Sprockets for Gulp, we’ll all have to learn the new way of creating and managing assets. Document what were your alternatives, why you made the decision and how that will affect (positively and potentially negatively) the team and the project. That will also be useful if the spike runs out of time and we want to come back to it later. That important knowledge won’t depend on one developer’s memory. It will be here forever and anyone will know where to start. It can also be valuable if your project qualifies for any government R&amp;D tax credits program.</p><h4>Answer the three questions explicitly</h4><p>The goal is to answer them. So write them down in a way that is easy to spot immediately. Use titles or bold text to make them even more obvious. I like to write them down in order in the conclusion. It is also a summary of what will be useful for the next steps and they can contain short “pros and cons”, a list of caveats or other possible alternatives found. Keep it short, but very dense in information.</p><h4>Abuse your tools</h4><p>We document our spikes in Github because it’s where they are defined. They are simply GitHub issues and we use ZenHub to estimate, prioritize and move them on an agile board. So, at every step, we document via rich comments, links, images, and any other GitHub feature. We don’t need another software or web app and we like to keep everything at the same place. Your documentation should be easy to find. You should not try to over engineer the flow and lose time just to start documenting. As in development, it is easy to break the research flow. Your focus is more important than some fancy feature of a new tool.</p><h4>Use Markdown</h4><ul><li>Markdown is cool.</li><li>Markdown is so fast to write</li><li>Markdown is simple</li><li><strong>-&gt; You don’t lose time formatting it. &lt;-</strong></li><li>It is nice to read</li><li>it’s an effective tool to communicate with bullet points, lists, titles, links, etc.</li><li>You can create yourself templates to fill</li></ul><p>That point is also to emphasize on the importance of your focus. Of course you can use another format or a document editor or Google docs. But don’t do it at the cost of your flow.</p><h3>The definition of “done” and “success”</h3><p>When is a spike “done”? When time’s out? When all the questions are answered? The answer is, whichever comes first.</p><p>If the time runs out, “we don’t know yet” is a perfectly acceptable answer to “is it feasible?”. But you still have to produce the documentation on what you tried or learned so any other team member could continue if it is decided to resume the spike. If you have some kind of code review process, you can totally have the same process to review what documentation has been produced. Because we are using Github, we can comment, ask questions and suggest edits to improve the documentation of the spike.</p><p><strong><em>Done</em> does not mean <em>success</em>.</strong> Success means that we can make a decision based on the conclusions.</p><blockquote><strong>Spike:</strong> Should we use a CDN to save money? <br><strong>Answer:</strong> No. <br>Our servers resources are underused right now (insert graph here). A CDN would be additional infrastructure costs and development is needed.</blockquote><p>That spike is a success. Even if the answer is no, we have knowledge about that problem. We will maybe know how much third party CDN cost, when we will reach the point that a CDN will save some server resource and what is the development effort will be.</p><p>The way you include spikes in your flow is up to you. But documenting a spike requires some rigor. I started using those guidelines for myself and I got immediate positive feedback on my work. I decided to document them for my team and we saw immediate benefits for it. Defining a spike got easier. The time spent on a spike is more valuable. Deciding how much time to spend is also easier.</p><p>Share this post if you think it could be useful for your team or developer friends. Your product owner will owe you a high five. If you have similar guidelines or you do something that we should try, please, send it to me. We always want to improve our process.</p><p>Here is a gift, just for you my friends:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*nIs6bGj5D55faa0xpPSZdw.jpeg" /></figure><p>You’re welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a43f0d19967" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Work in progress solution for RSpec and VCR]]></title>
            <link>https://medium.com/programming-problem-solving-logbook/work-in-progress-solution-for-rspec-and-vcr-ce985b7e418d?source=rss-6d5af0f54123------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce985b7e418d</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Sophie Déziel]]></dc:creator>
            <pubDate>Sat, 05 Dec 2015 22:28:07 GMT</pubDate>
            <atom:updated>2015-12-05T22:34:24.089Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wasted time on trying to understand why your tests don’t pass and should (or pass and should not) only to realize that VCR is using a cassette that you should have deleted?</p><p>Don’t get me wrong, VCR is very useful. It caused me a lot of problems and I thought many times of not using it anymore. Let’s be positive and call those frustrating problems “experience”.</p><p>One thing I did today to solve one particular problem is worth sharing with the world. I am working on a wrapper for a RESTful API and using Test-Driven-Development. However, to make actual external calls with VCR to make sure that my code is actually working, I have to put in my spec file something like that:</p><pre>before do <br>  WebMock.allow_net_connect! <br>  WebMock.disable! <br>  VCR.eject_cassette <br>  VCR.turn_off!(:ignore_cassettes =&gt; true)<br>end</pre><p>I was worried I would forget to remove that snippet before commiting my code or forget to run the tests once with VCR reactivated to records the cassettes before CI would run the test suite. It’s not a big deal, but enough to bother me.</p><p>Also, since that snippet is not commited and is nowhere in the codebase, I have to find it in my Gists and copy-paste it. Another minor annoyance that adds up.</p><p>I decided to improve that by using a `wip` tag. Easy to add and easy to remove. To make sure that I would not forget to remove it, it raises a warning at the end of the test suite if one is present.</p><p>First, I created the hook in spec_helper.rb:</p><pre>wip_count = 0<br>RSpec.configure do |config|<br>  config.around(:example, :wip) do |exampe|<br>    WebMock.allow_net_connect!<br>    VCR.turned_off(:ignore_cassettes =&gt; true) { exampe.run }<br>    WebMock.disable_net_connect!<br>    wip_count += 1<br>  end<br>end</pre><p>Then, with that `wip_count`, I can raise the warning:</p><pre>wip_count = 0<br>RSpec.configure do |config|<br>  config.around(:example, :wip) do |exampe|<br>    WebMock.allow_net_connect!<br>    VCR.turned_off(:ignore_cassettes =&gt; true) { exampe.run }<br>    WebMock.disable_net_connect!<br>    wip_count += 1<br>  end</pre><pre>  config.after(:suite) do<br>    warn &quot;\n\nWarning: don&#39;t forget to remove the &#39;wip&#39; tag before commiting your work&quot;.yellow unless wip_count.zero?<br>  end<br>end</pre><p>Now, in my spec files, I can use the tag to disable VCR on demand:</p><pre>describe &quot;#perform&quot; do<br> it &quot;makes a call to the API&quot;, :wip do<br>  # the test</pre><p>And when I run my tests, I get the results I expected!</p><pre>rspec ./spec/lib/API/request_spec.rb<br>...F.F...</pre><pre>Warning: don’t forget to remove the ‘wip’ tag before commiting your work</pre><pre>Failures:</pre><p>Bonus: I can also run only the examples with the `wip` tag!!</p><pre>rspec ./spec/lib/API/request_spec.rb --tag wip<br>Run options: include {:wip=&gt;true}</pre><pre>FF</pre><pre>Warning: don’t forget to remove the ‘wip’ tag before commiting your work</pre><pre>Failures:</pre><p>I hope you’ll find that tip useful and if you have any improvement suggestion, please, share them with me in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce985b7e418d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/programming-problem-solving-logbook/work-in-progress-solution-for-rspec-and-vcr-ce985b7e418d">Work in progress solution for RSpec and VCR</a> was originally published in <a href="https://medium.com/programming-problem-solving-logbook">Programming Problems Solving Log Book</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails multiple checkboxes]]></title>
            <link>https://medium.com/programming-problem-solving-logbook/rails-multiple-checkboxes-e9c4c7fda356?source=rss-6d5af0f54123------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9c4c7fda356</guid>
            <dc:creator><![CDATA[Sophie Déziel]]></dc:creator>
            <pubDate>Thu, 16 Jul 2015 05:27:54 GMT</pubDate>
            <atom:updated>2019-05-03T23:04:39.063Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, I had to create a form for business hours. It seems simple, but there is a lot to think about. Once the model logic completed, I faced a funny problem about multiple checkboxes used to populate an array of weekdays.</p><p>So, lets say you want a form with a certain number of options, you want to know which one the user checked, you want an array of it to pass into another method or object and you don’t care about the unchecked ones. There is a lot of reasons you wan’t to have a clean array:</p><ol><li>You don’t want the null, false or “0” values to pollute your database</li><li>You have validations to make on each of the values</li><li>Any other good reason to require an array containing only the values</li></ol><p>My first form attempt with the multiple option:</p><pre>// app/views/week_selections/_form.html.slim</pre><pre>= form_for @week_selection do |f|<br>  - days = [&#39;Mon&#39;, &#39;Tue&#39;, &#39;Wen&#39;, &#39;Thu&#39;, &#39;Fri&#39;, &#39;Sat&#39;, &#39;Sun&#39;]<br>  - days.each do |day|<br>    = f.check_box :days, { multiple: true }, day<br>    label day<br>  = f.submit</pre><p>In my controller, the params was a bit wrong:</p><pre># app/controllers/week_selections_controller.rb<br># I selected Mon and Tue</pre><pre>...</pre><pre>def form_params<br>  params.require(:week_selection).permit(days:[])<br>end</pre><pre>form_params # =&gt; { week_selection: { days: [&quot;0&quot;, &quot;Mon&quot;, &quot;0&quot;, &quot;Tue&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;] }</pre><blockquote>What happened?</blockquote><p>The checkbox helper has an option “unchecked_value” (<a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-check_box">doc</a>) and its default is “0”. If you set that option to false, you can get rid of all those unwanted values in your array!!</p><pre>// app/views/week_selections/_form.html.slim</pre><pre>= form_for @week_selection do |f|<br>  - days = [&#39;Mon&#39;, &#39;Tue&#39;, &#39;Wen&#39;, &#39;Thu&#39;, &#39;Fri&#39;, &#39;Sat&#39;, &#39;Sun&#39;]<br>  - days.each do |day|<br>    = f.check_box :days, { multiple: true }, day, false<br>    label day<br>  = f.submit</pre><p>See the beautifully clean array:</p><pre>form_params # =&gt; { week_selection: { days: [&quot;Mon&quot;, &quot;Tue&quot;] }</pre><pre># YAY! No need to clean the values in the controller!</pre><p>That simple option costed me too much time today. I wish I knew that before. But eh, I hope that this note will help everybody on the internet!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9c4c7fda356" width="1" height="1" alt=""><hr><p><a href="https://medium.com/programming-problem-solving-logbook/rails-multiple-checkboxes-e9c4c7fda356">Rails multiple checkboxes</a> was originally published in <a href="https://medium.com/programming-problem-solving-logbook">Programming Problems Solving Log Book</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A: The Asset Pipeline]]></title>
            <link>https://medium.com/abc-of-ruby-on-rails/a-the-asset-pipeline-92617f8a4c02?source=rss-6d5af0f54123------2</link>
            <guid isPermaLink="false">https://medium.com/p/92617f8a4c02</guid>
            <dc:creator><![CDATA[Sophie Déziel]]></dc:creator>
            <pubDate>Mon, 28 Jul 2014 23:04:58 GMT</pubDate>
            <atom:updated>2018-01-31T00:17:02.207Z</atom:updated>
            <content:encoded><![CDATA[<h4>The ABC of Ruby on Rails</h4><h3>Note that this article was written in 2014, as the Asset Pipeline was a new a confusing feature of Rails. As this can be relevant maintaining legacy applications, this article is aging quickly and becoming largely outdated.</h3><p>For the first letter of my <a href="https://medium.com/@sophiedeziel/abc-of-ruby-on-rails-introduction-d84f1c942d81">ABC of Ruby on Rails</a>, I chose to talk about a simple and powerful, but often misunderstood feature of Rails. The Asset Pipeline is a framework designed to help developers to organize their files and magically compile higher-level languages like CoffeeScript and Sass, package them, minify them and compress them. Because of its simplicity, it’s a no-brainer to directly dive into the code. Yet we need to understand how it work to unleash its power.</p><h2>The basics</h2><h3>File organization</h3><p>One of the first things you’ll learn in Rails tutorials is where to put your files and how to access them in your views. Without going into all the details, there are three folders where you can organize your assets:</p><pre>app/assets &lt;- app specific assets<br>lib/assets/ &lt;- assets shared through your different projects<br>vendor/assets/ &lt;- Assets from other sources (ex. Backbone.js)</pre><p>When you start a new project, those three folders contain an <em>images</em>, <em>javascripts</em> and <em>stylesheets</em> folder. You can then create any folder to organize your files and put everything where you want it. Rails will magically deliver the contents with the URL <a href="#">http://yourproject/assets/</a></p><p>When an asset is requested by the browser, Rails looks in each of these folders in the same order as above until it finds the right file to serve. Be careful with the way you name your files to prevent overriding lib or vendor assets.</p><h3>File concatenation</h3><p>Another important part of the assets pipeline that is very useful in production to reduce the HTTP requests numbers and speed up your app is file concatenation. Your Javascript and CSS files are grouped in two big .js and .css master files, and the file names are marked with a fingerprint to effectively handle the cache.</p><h3>Compilation</h3><p>My favourite part of the assets pipeline is the compilation feature. Before concatenating your files, it compiles your CoffeeScript and Sass files. It can also handle Less with the <em>less-rails </em>gem. It can also perform many compilation cycles to evaluate Erb into your files — to use Rails helpers, for example. All you have to do is to chain the extensions in the right order:</p><pre>script.js &lt;- no precompilation<br>script.js.erb &lt;- compiles Erb in your Javascript<br>script.js.coffee &lt;- CoffeeScript to Javascrip<br>script.js.coffee.erb &lt;- Erb compilation, then CoffeeScript<br>script.js.erb.coffee &lt;- Won&#39;t work because CoffeeScript can&#39;t interpret Erb</pre><h2>How it works</h2><p>Assets serving <em>does not work the same way</em> in the development environment as it does in the production environment. Since the asset pipeline was introduced in Rails 3.1, many rails developers have faced this problem at least once:</p><h3>My file was accessible in development, why isn&#39;t it showing up in production?</h3><h4>The reason is: <strong><em>Precompilation.</em></strong></h4><p>In the production environment, assets aren&#39;t served directly from their source. You have to run the command:</p><pre>rake assets:precompile</pre><p>Files are compiled and concatenated into the master files. These files are saved into the <em>public/assets</em> folder and the fingerprint is added to the file name to optimize the client-side cache. Not all files are precompiled because you have to tell Rails in what order they should be concatenated.</p><h3>Require statement</h3><p>By default, you already have an <em>application.js </em>and <em>application.css </em>files when you start a new Rails app. They are called <em>manifests. </em>This is where you specify which files are needed with the require statements. The default Javascript manifest contains the following lines:</p><pre>//= require jquery<br>//= require jquery_ujs<br>//= require turbolinks<br>//= require_tree .</pre><p>This means <em>jquery</em>, <em>jquery_ujs</em> and <em>turbolinks</em> will be concatenated first, and then all the other files contained in the <em>app/assets/javascripts</em> will be added at the end. To load the master files into your pages, the only thing you’ll have to do is to put the following lines in the <em>Head</em> element of your layout:</p><pre>&lt;%= stylesheet_link_tag &quot;application&quot;, media: &quot;all&quot; %&gt;<br>&lt;%= javascript_include_tag &quot;application&quot; %&gt;</pre><p>There are several other options, that you can find in the <a href="http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives">Rails Documentation</a>.</p><h2>Strategies</h2><p>Here are several strategies and guidelines to fulfill the needs of your different projects. Feel free to criticize them in the comments, everything can always be improved.</p><h3>The “Require all” strategy</h3><p>This is the easiest one to adopt because it is the default one. The <em>require_tree</em> statement does almost all the job for you and all you have to do is to write your files. You can also create some subdirectories to keep everything clear and they will be added recursively. No files are left behind.</p><p>Using this strategy, you have to make sure that you name all your classes, methods and HTML elements correctly to avoid overriding something you shouldn&#39;t. You should only use it for small Rails app that doesn&#39;t have a lot of assets. Even if it is easy to change as your app grows, I don’t like this approach because it doesn&#39;t force you to think about architecture and how to optimize your JS and CSS structure.</p><h3>Extract controller specific parts</h3><p>When your app starts to grow, it’s a good thing to think about what’s used in some specific parts of your app and what’s not. Your precompiled files will become larger with many libraries and a lot of page-specific scripts or styles. A good way to reduce the size of your master files is to extract from the trunk everything that belongs to a controller scope in individual files named after it’s respective controller.</p><p>Now, you don’t want the entire tree to be concatenated into the master files. Your file structure could be like:</p><pre>app<br> +-- assets<br>      +-- images<br>      +-- javascripts<br>      |    +-- application<br>      |    +-- controllers<br>      |    +-- application.js<br>      |<br>      +-- stylesheets<br>           +-- application<br>           +-- controllers<br>           +-- application.css</pre><p>Then, your manifests should look like:</p><pre># application.js<br> <br>//= require jquery<br>//= require jquery_ujs<br>//= require turbolinks<br>//= require_tree ./application<br> </pre><pre># application.css</pre><pre>/*<br> *= require jquery<br> *= require jquery_ujs<br> *= require turbolinks<br> *= require_tree ./application<br> */</pre><p>That means that your master files will include only what’s in the application folder. That’s where you should put your scripts that are shared through your applications. Then, to access your controller specific files in your layouts:</p><pre>&lt;%= stylesheet_link_tag &quot;application&quot;, media: “all” %&gt;<br>&lt;%= stylesheet_link_tag &quot;controllers/#{params[:controller]}&quot;, media: “all” %&gt;</pre><pre>&lt;%= javascript_include_tag &quot;application&quot; %&gt;<br>&lt;%= javascript_include_tag &quot;controllers/#{params[:controller]}&quot; %&gt; </pre><p>This will work in development, but it’s not accessible yet in production because controller-specific files must be precompiled. Add this line to your <em>config/application.rb</em>, with your other configs:</p><pre>config.assets.precompile += [&#39;controllers/*.js&#39;, &#39;controllers/*.css&#39;]</pre><p>Then in the terminal:</p><pre>rake assets:precompile</pre><h3>Scope specific files</h3><p>I prefer another way to organize my assets, a bit more complex and very well adapted for application with many different parts — like admin, e-shop and user dashboard, for example. I will create another article to describe it in detail.</p><h2>Conclusion</h2><p>There is a lot more to say about the assets pipeline. This article was about files organization and how they are served. I suggest you to read about Coffeescript, Sass and Erb to use them efficiently with the assets pipeline. For example, it is possible to use Erb to reference images paths. You can also extend the asset pipeline <a href="http://www.davidverhasselt.com/2013/10/27/how-to-write-a-custom-asset-pipeline-processor-to-compress-image-files/">to compress images</a>.</p><p>If you enjoyed this article, I suggest you to follow my Medium collection, <a href="https://medium.com/abc-of-ruby-on-rails">ABC of Ruby on Rails</a>. You can also follow me on Twitter, <a href="https://twitter.com/sophiedeziel">@sophiedeziel</a>. And feel free to ask me questions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92617f8a4c02" width="1" height="1" alt=""><hr><p><a href="https://medium.com/abc-of-ruby-on-rails/a-the-asset-pipeline-92617f8a4c02">A: The Asset Pipeline</a> was originally published in <a href="https://medium.com/abc-of-ruby-on-rails">ABC of Ruby on Rails</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ABC of Ruby on Rails: Introduction]]></title>
            <link>https://medium.com/abc-of-ruby-on-rails/abc-of-ruby-on-rails-introduction-d84f1c942d81?source=rss-6d5af0f54123------2</link>
            <guid isPermaLink="false">https://medium.com/p/d84f1c942d81</guid>
            <dc:creator><![CDATA[Sophie Déziel]]></dc:creator>
            <pubDate>Wed, 09 Jul 2014 03:32:45 GMT</pubDate>
            <atom:updated>2015-01-11T02:37:51.731Z</atom:updated>
            <content:encoded><![CDATA[<h4>Because we must start somewhere</h4><p>I’ve been reading a lot of cool stories here on Medium. I follow some interesting collections about programing, entrepreneurship, lifehacks and success stories. And I told to myself : <em>hey, I’d like to write too! </em>So I read a lot of stories telling how to write stories. And then I read stories about stoping to read and starting to write. uh.</p><p>Soooo… This is my very first one, in my very first collection. And here’s the idea:</p><blockquote>For each letter in the alphabet, I’ll explain a Ruby on Rails concept.</blockquote><p>From basic to advanced Rails programming, one story at the time. Please, feel free to give me suggestions. I have to use every single letters and I’d like to know what you want to learn.</p><h3>The planned alphabet</h3><p>You’ll see here the planned topics, the links to the ones that’s written and you can help me filling the blanks with your ideas. I’ll try to publish twice a month, then the entire project will take about a year.</p><p><a href="https://medium.com/abc-of-ruby-on-rails/92617f8a4c02"><strong>A: Asset Pipeline</strong></a><strong><br>B: Backbone Integration<br>C: Config<br>D: Database<br>E: Engines<br>F: Faraday<br>G: Gems<br>H: Helpers<br>I: I18n (</strong><em>Working on it)</em><strong><br>J: Jobs </strong>(<em>Also working on a draft</em>)<strong><br>K: Kaminari<br>L: Layouts<br>M: Mailer<br>N: Namespaces<br>O: Omniauth<br>P: Plugins<br>Q: Query Interface<br>R: Rake<br>S: Scaffold<br>T: Testing<br>U: Uglifier<br>V: Views<br>W: Workers<br>X: XML<br>Y: Yaml<br>Z: Zip</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d84f1c942d81" width="1" height="1" alt=""><hr><p><a href="https://medium.com/abc-of-ruby-on-rails/abc-of-ruby-on-rails-introduction-d84f1c942d81">ABC of Ruby on Rails: Introduction</a> was originally published in <a href="https://medium.com/abc-of-ruby-on-rails">ABC of Ruby on Rails</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>