<?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 Ameer Hamza Mushtaq on Medium]]></title>
        <description><![CDATA[Stories by Ameer Hamza Mushtaq on Medium]]></description>
        <link>https://medium.com/@eboxameer?source=rss-ff2fbbabfaf2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NZdhA-0pwdxhGkf8ZkYaMQ.png</url>
            <title>Stories by Ameer Hamza Mushtaq on Medium</title>
            <link>https://medium.com/@eboxameer?source=rss-ff2fbbabfaf2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:10:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eboxameer/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[Understanding .detect in Ruby on Rails]]></title>
            <link>https://medium.com/@eboxameer/understanding-detect-in-ruby-on-rails-b057ac6451b1?source=rss-ff2fbbabfaf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b057ac6451b1</guid>
            <dc:creator><![CDATA[Ameer Hamza Mushtaq]]></dc:creator>
            <pubDate>Mon, 07 Apr 2025 18:08:55 GMT</pubDate>
            <atom:updated>2025-04-07T18:08:55.270Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding .detect in Ruby on Rails</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JPvnqat_uYQnzThXuvRKqQ.jpeg" /><figcaption>You need to find the <strong>first</strong> match?</figcaption></figure><p>In Ruby on Rails, developers often work with collections of objects — whether it’s ActiveRecord models, arrays, or hashes. While Rails adds many powerful tools on top of Ruby, sometimes the core Ruby methods are all you need. One such handy method is .detect.</p><h3>What is .detect?</h3><p>.detect is a method from Ruby&#39;s Enumerable module (so it works on arrays, hashes, and other enumerable collections). It is used to <strong>find the first element in a collection that meets a certain condition</strong>.</p><p>It’s an alias for .find — both work the same way.</p><pre>collection.detect { |element| condition }</pre><p>Or using the more common alias:</p><pre>collection.find { |element| condition }</pre><h3>Example in a Rails Context</h3><p>Imagine you have a list of users:</p><pre>users = User.all</pre><p>You want to find the first user whose email is john@example.com. You could use .detect like this:</p><pre>user = users.detect { |u| u.email == &#39;john@example.com&#39; }</pre><p>This will return the first matching user or nil if none is found.</p><h3>How is .detect different from .select?</h3><ul><li>.select returns <strong>all</strong> matching elements:</li></ul><pre>users.select { |u| u.active? } # returns an array of all active users</pre><p>.detect returns <strong>only the first</strong> match:</p><pre>users.detect { |u| u.active? } # returns the first active user</pre><p>This makes .detect more efficient when you&#39;re only interested in a single match.</p><h3>Using .detect with ActiveRecord</h3><p>Although .detect is useful, when you&#39;re working with ActiveRecord, <strong>it&#39;s better to use SQL queries</strong> for efficiency. .detect loads all records into memory and then iterates in Ruby, while ActiveRecord queries are performed directly in the database.</p><h3>When to Use .detect</h3><p>Use .detect when:</p><ul><li>You’re working with in-memory collections (not ActiveRecord relations).</li><li>You need to find the <strong>first</strong> match.</li><li>Performance isn’t critical or the dataset is small.</li></ul><h3>Summary</h3><ul><li>.detect (aka .find) returns the first element that meets a condition.</li><li>It works on any Enumerable object.</li><li>It’s a Ruby method, not specific to Rails.</li><li>Prefer ActiveRecord query methods (.find_by, .where) when dealing with models.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b057ac6451b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step by Step Form Submission | A Ruby Gem for Multi Step Wizards | Wicked Gem]]></title>
            <link>https://medium.com/@eboxameer/step-by-step-form-submission-a-ruby-gem-for-multi-step-wizards-wicked-gem-69fe55f96e7b?source=rss-ff2fbbabfaf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/69fe55f96e7b</guid>
            <dc:creator><![CDATA[Ameer Hamza Mushtaq]]></dc:creator>
            <pubDate>Tue, 06 Feb 2024 11:56:58 GMT</pubDate>
            <atom:updated>2024-02-06T20:20:41.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5jDnTexSxAKIeBp4XgzU8w.jpeg" /><figcaption>Multi Step Form Submission</figcaption></figure><p>In the world of web development, there often arises a need to guide users through a series of steps to complete a task or process. This could be anything from signing up for a service to filling out a complex form. Managing these multi-step processes efficiently and intuitively is crucial for providing a seamless user experience. That’s where the Wicked gem comes into play.</p><h3>What is Wicked?</h3><p>Wicked is a Ruby gem designed to simplify the implementation of multi-step wizard forms in Rails applications. It provides a clean and intuitive way to define and manage the steps of a wizard, making it easier for developers to create complex user flows without writing repetitive code.</p><h3>Key Features</h3><h4>1. Easy Integration</h4><p>Wicked seamlessly integrates with Rails applications, allowing developers to define wizard steps directly within their controllers.</p><h4>2. Flexible Configuration</h4><p>Developers have full control over the configuration of each wizard step, including the ability to define custom actions and validations.</p><h4>3. Customizable Views</h4><p>Wicked provides built-in support for custom views, making it easy to create visually appealing and user-friendly wizard interfaces.</p><h4>4. RESTful Routes</h4><p>The gem automatically generates RESTful routes for each step of the wizard, simplifying navigation and URL management.</p><h4>5. Persistence</h4><p>Wicked supports persistence across wizard steps, ensuring that user data is preserved even if they navigate away from the wizard and return later.</p><h3>Getting Started with Wicked</h3><p>To get started with Wicked, simply add it to your Gemfile and run bundle install:</p><pre>gem &#39;wicked&#39;</pre><p>Next, define your wizard steps in your controller using the wicked_steps method:</p><pre>class UsersController &lt; ApplicationController<br>  include Wicked::Wizard<br><br>  steps :personal_info, :contact_info, :confirmation<br>end</pre><p>Then, implement custom actions and validations for each step as needed:</p><pre>class UsersController &lt; ApplicationController<br>  include Wicked::Wizard<br><br>  steps :personal_info, :contact_info, :confirmation<br><br>  def update<br>    @user = current_user<br>    case step<br>    when :personal_info<br>      @user.update(personal_info_params)<br>    when :contact_info<br>      @user.update(contact_info_params)<br>    end<br>    render_wizard @user<br>  end<br>end</pre><p>Finally, create custom views for each step of the wizard to provide a seamless user experience:</p><pre>&lt;!-- app/views/users/personal_info.html.erb --&gt;<br>&lt;%= form_for @user, url: wizard_path do |f| %&gt;<br>  &lt;!-- Personal info form fields --&gt;<br>&lt;% end %&gt;</pre><h3>Conclusion</h3><p>With its simplicity and flexibility, the Wicked gem is an invaluable tool for developers looking to implement multi-step wizard forms in their Rails applications. Whether you’re building a signup process, a checkout flow, or any other complex user journey, Wicked provides the building blocks you need to create a smooth and intuitive experience for your users.</p><p>So why not give Wicked a try in your next Rails project? With its intuitive API and powerful features, it’s sure to become an essential part of your development toolkit. Happy coding!</p><p><strong>Official documentation url of wicked gem:</strong> <a href="https://github.com/zombocom/wicked">https://github.com/zombocom/wicked</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69fe55f96e7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Delegates | Ruby on Rails]]></title>
            <link>https://medium.com/@eboxameer/understanding-delegates-ruby-on-rails-613ffb249e0d?source=rss-ff2fbbabfaf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/613ffb249e0d</guid>
            <dc:creator><![CDATA[Ameer Hamza Mushtaq]]></dc:creator>
            <pubDate>Sat, 02 Sep 2023 18:12:58 GMT</pubDate>
            <atom:updated>2023-09-02T18:12:58.365Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*to30oNxTZINZ6cbH4v9Tbg.jpeg" /></figure><p><strong>Understanding Delegate Methods</strong></p><p><strong>Delegate</strong> methods are achieved using the delegate method in Ruby. The delegate method is part of the ActiveSupport library and simplifies the process of delegating methods to associated objects.</p><p><strong>Benefits of Delegate Methods:</strong></p><ol><li><strong>Code Organization:</strong> Delegate methods help keep the codebase organized by separating different concerns into distinct objects.</li><li><strong>Readability:</strong> By using delegate methods, you can improve code readability and maintainability as the code is more explicit about which methods are delegated.</li><li><strong>Flexibility:</strong> Delegate methods promote flexibility by allowing you to change the behavior of delegated methods in the associated object without affecting the delegating object.</li></ol><p><strong>Code Examples:</strong></p><p>For example I have a <strong>QueueItem</strong> and <strong>Video</strong> model.</p><pre><br>QueueItem &lt; ActiveRecord::Base<br>  belongs_to :video<br>end<br>Video &lt; ActiveRecord::Base<br>  has_many :queue_items<br>  belongs_to :category<br>end</pre><p>If I want to get the category object of the video in first queue_item, I may write</p><pre>queue_item = QueueItem.first<br>queue_item.video.category.name<br>#=&gt; &quot;Action&quot;</pre><p>It is kind of cumbersome. Instead of getting the object via model association, we can use delegate to help us.</p><pre>class QueueItem &lt; ActiveRecord::Base<br>  belongs_to :video<br> <br>  delegate :category, to: :video<br>end</pre><p>Then we can get the category by</p><pre>queue_item = QueueItem.first<br>queue_item.category.name<br>#=&gt; &quot;Action&quot;</pre><p><strong>Conclusion:</strong></p><p>Delegate methods are a powerful tool in Ruby that enhances code organization, readability, and flexibility. By using delegate methods, you can improve the separation of concerns and create cleaner, more maintainable code. They are particularly useful when you have objects with associated objects and you want to expose certain methods of the associated object through the main object.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=613ffb249e0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[View Component Gem | Creating Reusable, Testable & Encapsulated Components | Framework | Ruby on…]]></title>
            <link>https://medium.com/@eboxameer/view-component-gem-creating-reusable-testable-encapsulated-components-framework-ruby-on-7533eaecb104?source=rss-ff2fbbabfaf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7533eaecb104</guid>
            <dc:creator><![CDATA[Ameer Hamza Mushtaq]]></dc:creator>
            <pubDate>Sat, 17 Jun 2023 10:28:36 GMT</pubDate>
            <atom:updated>2023-06-17T10:30:36.752Z</atom:updated>
            <content:encoded><![CDATA[<h3>View Component Gem | Creating Reusable, Testable &amp; Encapsulated Components | Framework | Ruby on Rails</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FJn43jihZHB5rgDGu2dfyw.png" /></figure><p><strong>Introduction:</strong></p><p>In Ruby on Rails, managing complex view logic and keeping your views clean and organized can be a challenging task. However, with the help of the View Components gem, you can simplify your view code and improve reusability. In this blog post, we will explore the View Components gem and learn how to create, render, and customize components in Ruby on Rails applications.</p><p><strong>What are View Components?</strong></p><p>View Components provide a way to encapsulate reusable view logic into self-contained components. Each component consists of a Ruby class and an associated template file, making it easy to manage and reuse view code across different parts of your application.</p><p><strong>Installation:</strong></p><p>To start using View Components, you need to add the gem to your Gemfile and run the bundle install command. <strong>Open your Gemfile and add the following line:</strong></p><pre>gem &#39;view_component&#39;, require: &#39;view_component/engine&#39;</pre><p>After saving the Gemfile, run the following command in your terminal:</p><pre>bundle install</pre><p><strong>Creating a View Component:</strong></p><p>To create a new View Component, you can use the built-in generator provided by the View Components gem. Run the following command in your terminal:</p><pre>rails generate component Button</pre><p>This will generate the necessary files for the Button component:</p><ul><li>app/components/button_component.rb</li><li>app/components/button_component.html.erb</li></ul><p>Building the View Component: Open the button_component.rb file and define the logic and variables for the component. <strong>For example:</strong></p><pre># app/components/button_component.rb<br>class ButtonComponent &lt; ViewComponent::Base<br>  def initialize(text:, style: &#39;default&#39;)<br>    @text = text<br>    @style = style<br>  end<br>end</pre><p>In the corresponding template file button_component.html.erb, define the HTML structure of the component. For example:</p><pre>&lt;!-- app/components/button_component.html.erb --&gt;<br>&lt;button class=&quot;button-&lt;%= @style %&gt;&quot;&gt;<br>  &lt;%= @text %&gt;<br>&lt;/button&gt;</pre><p><strong>Rendering the View Component:</strong></p><p>To render the Button component, you can use the render method in your views or layouts. For example:</p><pre>&lt;%= render(ButtonComponent.new(text: &#39;Click me!&#39;, style: &#39;primary&#39;)) %&gt;</pre><p>By passing the necessary data to the component’s constructor, you can customize the appearance and behavior of the rendered component.</p><p><strong>Customizing and Reusing Components:</strong></p><p>One of the key benefits of View Components is their reusability. You can easily customize and reuse components across your application. For instance, you can modify the template or logic of the Button component to add additional CSS classes or dynamic data.</p><p>To reuse a component, simply render it in different views or layouts:</p><pre>&lt;%= render(ButtonComponent.new(text: &#39;Save&#39;, style: &#39;success&#39;)) %&gt;<br>&lt;%= render(ButtonComponent.new(text: &#39;Cancel&#39;, style: &#39;secondary&#39;)) %&gt;</pre><p>Conclusion: View Components in Ruby on Rails provide a powerful way to organize your view logic, improve reusability, and make your views more maintainable. With the View Components gem, you can encapsulate complex view code into self-contained components, making it easier to manage and enhance your application’s frontend.</p><p>In this blog post, we covered the basics of creating, rendering, and customizing View Components in Ruby on Rails. By following the provided examples, you can start leveraging the View Components gem to simplify your view code and enhance the overall development experience.</p><p>To learn more about advanced usage and best practices of View Components, refer to the official gem documentation <a href="https://github.com/ViewComponent/view_component">https://github.com/ViewComponent/view_component</a> and guides.</p><p><strong>Happy coding with View Components in Ruby on Rails!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7533eaecb104" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transactions | Ruby on Rails | Database Management Systems]]></title>
            <link>https://medium.com/@eboxameer/transactions-ruby-on-rails-database-management-systems-f6682452157b?source=rss-ff2fbbabfaf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6682452157b</guid>
            <dc:creator><![CDATA[Ameer Hamza Mushtaq]]></dc:creator>
            <pubDate>Mon, 29 May 2023 17:16:52 GMT</pubDate>
            <atom:updated>2023-05-29T17:17:10.518Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6rXB33OU0akatFuhbq8ejg.jpeg" /></figure><p><strong>Introduction:</strong><br>Transactions are an essential part of database management systems and play a crucial role in maintaining data integrity and consistency. In Ruby on Rails, transactions provide a way to group multiple database operations into a single unit, ensuring that either all operations succeed or none of them are applied.</p><p>In this blog post, we will explore the concept of transactions in Ruby on Rails and provide code examples to demonstrate their usage in various scenarios.</p><p><strong>What are Transactions?</strong><br>A transaction is a sequence of database operations that are treated as a single logical unit. These operations can include inserting, updating, or deleting records in the database. Transactions provide the ACID (Atomicity, Consistency, Isolation, Durability) properties, ensuring the integrity of data even in the presence of failures.</p><p><strong>Using Transactions in Ruby on Rails:</strong><br>In Ruby on Rails, transactions can be used at the model or controller level to encapsulate a group of database operations. Let’s explore some common use cases and see how transactions can be implemented.</p><p><strong>Example 1:</strong> Wrapping Transactions Around Database Operations in Models<br>In this example, we have an `Order` model with associated `Item` records. We want to create an order and its associated items in a single transaction.</p><pre>class Order &lt; ApplicationRecord<br>  def self.create_with_items(items)<br>    transaction do<br>      order = Order.create<br>      items.each do |item|<br>        order.items.create(name: item[:name], quantity: item[:quantity])<br>      end<br>      order<br>    end<br>  end<br>end</pre><p><strong>Example 2:</strong> <strong>Handling Exceptions in Transactions</strong><br>In this example, we have a `BankAccount` model with `withdraw` and `deposit` methods. We want to transfer funds from one account to another in a transaction and handle any exceptions that may occur.</p><pre>class BankAccount &lt; ApplicationRecord<br>  def transfer_funds(to_account, amount)<br>    transaction do<br>      withdraw(amount)<br>      to_account.deposit(amount)<br>    rescue =&gt; e<br>      raise ActiveRecord::Rollback, e.message<br>    end<br>  end<br><br>  private<br><br>  def withdraw(amount)<br>    # Logic to withdraw funds from the account<br>  end<br><br>  def deposit(amount)<br>    # Logic to deposit funds into the account<br>  end<br>end</pre><p><strong>Example 3: Transactions in Controller Actions</strong><br>In this example, we have an `OrdersController` with a `create` action that creates a new order and performs calculations on it within a transaction. If any validation errors occur, the transaction is rolled back.</p><pre>class OrdersController &lt; ApplicationController<br>  def create<br>    ActiveRecord::Base.transaction do<br>      @order = Order.create(order_params)<br>      @order.calculate_total<br>      @order.save!<br>    end<br>    redirect_to @order, notice: &#39;Order created successfully.&#39;<br>  rescue ActiveRecord::RecordInvalid =&gt; e<br>    flash.now[:alert] = &quot;Error creating order: #{e.message}&quot;<br>    render :new<br>  end<br>end</pre><p><strong>Example 4: Atomic Updates with Transactions</strong><br>In this example, we have an `InventoryController` with a `restock` action that updates the stock of a product and creates a restock log entry within a transaction. If any error occurs, the transaction is rolled back.</p><pre>class InventoryController &lt; ApplicationController<br>  def restock<br>    transaction do<br>      product = Product.find(params[:product_id])<br>      product.update_stock(params[:quantity])<br>      product.create_restock_log(params[:quantity])<br>    end<br>    redirect_to products_path, notice: &#39;Restock completed successfully.&#39;<br>  rescue =&gt; e<br>    flash.now[:alert] = &quot;Error restocking product: #{e.message}&quot;<br>    render :restock_form<br>  end<br>end</pre><p><strong>Conclusion:</strong><br>Transactions in Ruby on Rails provide a powerful mechanism for managing database operations in a consistent and reliable manner. By grouping related operations within a transaction, you can ensure that data integrity is maintained and that changes are atomic.</p><p>In this blog post, we have covered the basics of transactions in Ruby on Rails and provided code examples to demonstrate their usage in different scenarios. We explored how transactions can be used at the model and controller levels, as well as how they can handle exceptions and atomic updates.</p><p>Remember that transactions should be used judiciously and only when necessary. Overusing transactions can impact performance, as they lock database resources during their execution. It’s important to find the right balance between transactional integrity and performance optimization.</p><p>As you continue to work with Ruby on Rails and interact with databases, understanding and effectively using transactions will greatly enhance your ability to manage data consistency and handle complex operations.</p><p>We hope this blog post has provided you with a solid understanding of transactions in Ruby on Rails and how they can be applied in your applications. Start incorporating transactions into your codebase to ensure the reliability and integrity of your database operations.</p><p><strong>Happy coding!</strong></p><blockquote>“I fell in love with Ruby on Rails because it allowed me to build powerful web applications with elegance and simplicity. It’s like having a magic wand in my hands, turning complex problems into elegant solutions.” —</blockquote><blockquote><strong>Ameer Hamza Mushtaq</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6682452157b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Say Goodbye to Repeating Instance Variables | Keep your Controllers Organized and Maintainable |…]]></title>
            <link>https://medium.com/@eboxameer/say-goodbye-to-repeating-instance-variables-keep-your-controllers-organized-and-maintainable-6b278f5d2c25?source=rss-ff2fbbabfaf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b278f5d2c25</guid>
            <dc:creator><![CDATA[Ameer Hamza Mushtaq]]></dc:creator>
            <pubDate>Mon, 01 May 2023 11:07:48 GMT</pubDate>
            <atom:updated>2023-05-01T11:07:48.244Z</atom:updated>
            <content:encoded><![CDATA[<h3>Say Goodbye to Repeating Instance Variables | Keep your Controllers Organized and Maintainable | Decent Exposure Gem</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4QcE9QeBGSyBIVN4j7Jxg.png" /></figure><p><strong>Decent Exposure</strong> is a gem for Ruby on Rails that aims to simplify your controller code by allowing you to move your instance variable setup into a separate module. This gem was created by the software development company <strong>Hashrocket</strong>, and it’s available on <strong>GitHub</strong> at <a href="https://github.com/hashrocket/decent_exposure">https://github.com/hashrocket/decent_exposure</a>.</p><p><strong>Step 1:</strong> <strong>Install the Decent Exposure gem</strong></p><p>The first step is to install the Decent Exposure gem. Add the following line to your Gemfile:</p><pre>gem &#39;decent_exposure&#39;</pre><p>Then run bundle install to install the gem.</p><p><strong>Step 2: Define your exposure</strong></p><p>Next, we need to define our exposure. An exposure is a method that sets up an instance variable for use in a view or other controller method. We define exposures in a separate module that is included in our controller:</p><pre># app/controllers/posts_controller.rb<br><br>class PostsController &lt; ApplicationController<br>  include DecentExposure::Controller<br><br>  expose :posts do<br>    Post.all<br>  end<br><br>  def index<br>    # `posts` instance variable is already set up<br>  end<br><br>  def show<br>    # `post` instance variable is already set up<br>  end<br><br>  private<br><br>  def resource<br>    Post.find(params[:id])<br>  end<br>  expose :post, finder: :resource<br>end</pre><p>In this example, we’re defining an exposure called posts that returns all posts. We&#39;re also defining an exposure called post that uses a private method called resource to find the post with the given ID.</p><p><strong>Step 3: Use the instance variables in your views</strong></p><p>Now that we have defined our exposures, we can use the instance variables in our views:</p><pre># app/views/posts/index.html.erb<br><br>&lt;% @posts.each do |post| %&gt;<br>  &lt;h2&gt;&lt;%= post.title %&gt;&lt;/h2&gt;<br>  &lt;p&gt;&lt;%= post.body %&gt;&lt;/p&gt;<br>&lt;% end %&gt;</pre><p>In this example, we’re using the @posts instance variable to display a list of posts.</p><p><strong>Conclusion</strong></p><p>The Decent Exposure gem can help simplify your controllers and keep them clean. By defining your exposures in a separate module, you can move your instance variable setup out of your controller methods and into a more organized location. With Decent Exposure, your controllers can be more focused on handling user input and less focused on setting up instance variables. You can find more information about Decent Exposure, including the official documentation, on GitHub at <a href="https://github.com/hashrocket/decent_exposure">https://github.com/hashrocket/decent_exposure</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b278f5d2c25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use YAML files to store data | Ruby on Rails | Data outside database]]></title>
            <link>https://medium.com/@eboxameer/how-to-use-yaml-files-to-store-data-ruby-on-rails-data-outside-database-db295a8a5281?source=rss-ff2fbbabfaf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/db295a8a5281</guid>
            <dc:creator><![CDATA[Ameer Hamza Mushtaq]]></dc:creator>
            <pubDate>Thu, 13 Apr 2023 15:42:47 GMT</pubDate>
            <atom:updated>2023-04-13T15:42:47.949Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m_VQ4GlAoFi--d8Gbsf0Kw.png" /></figure><p><strong>YAML</strong> is a human-readable data serialization format. It’s often used to store configuration data and other structured information. In Rails, YAML files can be used to store data as well. In this post, we’ll look at how to use YAML files to store data in Rails.</p><p><strong>Step 1: Create a YAML file</strong></p><p>First, create a YAML file in the config folder of your Rails application. For example, if you want to store data about countries, you could create a file called <strong>countries.yml</strong>:</p><pre># config/countries.yml<br><br>- name: United States<br>  code: US<br>- name: Canada<br>  code: CA<br>- name: United Kingdom<br>  code: UK</pre><p>In this example, we have a list of countries with their names and country codes.</p><p><strong>Step 2: Load the YAML file</strong></p><p>Next, we need to load the YAML file into our Rails application. We can do this by creating a YAML object and passing in the contents of the YAML file:</p><pre># config/initializers/countries.rb<br><br>COUNTRIES = YAML.load_file(&quot;#{Rails.root}/config/countries.yml&quot;)</pre><p>In this example, we’re creating a constant called COUNTRIES and assigning it the contents of the <strong>countries.yml</strong> file.</p><p><strong>Step 3: Access the data</strong></p><p>Now that we have loaded the YAML file, we can access the data in our Rails application. For example, let’s say we want to display a list of countries in a dropdown menu. We can do this in our view:</p><pre># app/views/countries/index.html.erb<br><br>&lt;%= select_tag &#39;country&#39;, options_for_select(COUNTRIES.map { |c| [c[&#39;name&#39;], c[&#39;code&#39;]] }) %&gt;</pre><p>In this example, we’re using the select_tag helper to create a dropdown menu with the names of the countries as the options and the country codes as the values.</p><p><strong>Conclusion</strong></p><p>YAML files can be a useful way to store data in Rails. By following the steps outlined in this post, you can easily load and access data from a YAML file in your Rails application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db295a8a5281" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RuboCop | Your Ruby on Rails Code Quality Enforcer]]></title>
            <link>https://medium.com/@eboxameer/rubocop-your-ruby-on-rails-code-quality-enforcer-ce4c36a66e26?source=rss-ff2fbbabfaf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce4c36a66e26</guid>
            <dc:creator><![CDATA[Ameer Hamza Mushtaq]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 17:27:54 GMT</pubDate>
            <atom:updated>2023-04-10T17:28:18.936Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*mkAsZNQ3GGK_80lrCp_UJA.png" /></figure><p>As a Ruby on Rails developer, you want to ensure that your code is maintainable, efficient, and adheres to best practices. One tool that can help you achieve this is RuboCop.</p><p>RuboCop is a free and open-source static code analysis tool that checks your code for potential issues and style violations. It enforces a set of rules and guidelines based on the Ruby Style Guide, ensuring that your code is consistent and follows best practices.</p><p>Using RuboCop is easy. Simply install the gem and run it on your codebase. RuboCop will scan your files, checking for issues such as unused variables, unused methods, and style violations. It will then provide you with a detailed report of any issues it finds, along with suggestions for how to fix them.</p><p>One of the key benefits of RuboCop is that it helps you catch potential issues early in the development process. By catching issues before they become problems, you can save time and effort in the long run. Additionally, RuboCop’s strict style guidelines help ensure that your code is consistent and easy to read, making it easier for other developers to understand and maintain.</p><p>RuboCop is highly configurable, allowing you to customize its rules to fit your specific needs. You can configure RuboCop to ignore certain files or directories, or to enforce rules based on your team’s preferences.</p><p>Overall, RuboCop is a valuable tool for Ruby on Rails developers who want to ensure that their code is of high quality and adheres to best practices. By catching potential issues early in the development process and enforcing strict style guidelines, RuboCop can help you write better code and save time and effort in the long run. So why not give it a try on your next project?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce4c36a66e26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Security Analysis Tool For Ruby on Rails | Brakeman]]></title>
            <link>https://medium.com/@eboxameer/security-analysis-tool-for-ruby-on-rails-brakeman-183df70524d5?source=rss-ff2fbbabfaf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/183df70524d5</guid>
            <dc:creator><![CDATA[Ameer Hamza Mushtaq]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 14:58:02 GMT</pubDate>
            <atom:updated>2023-04-10T14:58:02.023Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xTd-iR55yTOUaFxx4Us-4Q.png" /></figure><p>Hey Rubyist, as you guys are Ruby on Rails developer, you may be interested in checking out the Brakeman security analysis tool. Brakeman is a free and open-source tool that helps you identify security vulnerabilities in your Rails applications by scanning your code for potential issues.</p><p>With Brakeman, you can quickly and easily identify common security risks such as SQL injection, cross-site scripting, and authentication issues. The tool provides detailed reports and suggestions for how to fix any vulnerabilities it finds, helping you make your applications more secure.</p><p>If you’re interested in learning more or trying out Brakeman for yourself, you can check out their website at <a href="https://lnkd.in/d9sMqA4b">https://lnkd.in/d9sMqA4b</a>. Let’s all work together to make our Ruby on Rails applications as secure as possible!”</p><p><a href="https://www.linkedin.com/feed/hashtag/?keywords=developer&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7051204367768530944">#developer</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=security&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7051204367768530944">#security</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=learning&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7051204367768530944">#learning</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=rubyonrails&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7051204367768530944">#rubyonrails</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=ruby&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7051204367768530944">#ruby</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=rubydeveloper&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7051204367768530944">#rubydeveloper</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=softwareengineer&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7051204367768530944">#softwareengineer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=183df70524d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>