How to Add Image in Ruby on Rails? Last Updated : 17 Sep, 2024 Comments Improve Suggest changes Like Article Like Report In Ruby on Rails, there are several ways to add images to your application. In this article, we will see one of the common methods which is using an assets pipeline.Steps on How to Create a ProjectStep 1: Create a demo project using the command below. It will create a project named 'myapp' in the current directory. Then use the second command to get into your project directory.rails new myappcd myappCreate a ProjectStep 2: Now, we will create a controller and view using the following command. This command creates a controller file named 'images_controller.rb' in ‘app/controllers’ and its view file 'index.html.erb' in ‘app/views/home’. This command also creates a route file 'config/routes.rb'. rails generate controller Images indexCreate Controller and ViewStep 3: To display our index page, make changes in the 'config/routes.rb' file. Adding the following line in the file will set our index page as root.Rails.application.routes.draw do root 'images#index'endSteps to Add Images Using AssetsStep 1: Now, we'll add an image to the project. You can use any image you want. For example, let's say we have an image named 'GeeksforGeeks.png'. Place this image file in the 'app/assets/images' directory of your Rails project.Add Image to PathStep 2: To display the image, Open the 'app/views/images/index.html.erb' file and add the following lines.<h1>GeeksforGeeks</h1><%= image_tag("GeeksforGeeks.png") %>Step 3: Start the server using below command and open "http://localhost:3000/" in your browser.rails serverOutput:Output Comment More infoAdvertise with us Next Article How to Add Image in Ruby on Rails? M mukeshprajtjp2 Follow Improve Article Tags : Ruby RubyonRails Similar Reads How to Add CSS in Ruby on Rails? This article focuses on discussing how to add Cascading Style Sheets (CSS) in Ruby on Rails. Table of Content Using SCSSUsing Plain CSSUsing Inline StylesUsing External CSS FrameworksComparison of Different ApproachesAdditional ConsiderationsConclusionUsing SCSSSCSS (Sass) is a preprocessor that ext 4 min read How to create model in Ruby on Rails? In Ruby on Rails, models are like the organizers of your data. They handle interactions with your database. Think of them as the brains of your application, responsible for managing and manipulating data. They represent the structure and behavior of the information your app works with. So, whenever 4 min read How to create API in Ruby on Rails? Building APIs with Ruby on Rails: A Step-by-Step GuideRuby on Rails (Rails) is a popular framework for web development, known for its convention over configuration approach. It also excels in creating robust and maintainable APIs (Application Programming Interfaces). APIs act as intermediaries, allo 3 min read How to Install Ruby on Rails on MacOS? Ruby on Rails, also known as rails, is a server-side web application development framework written in the Ruby programming language. David Heinemeier Hansson developed it under the MIT License. It supports MVC (model-view-controller) architecture that provides a default structure for databases, web 2 min read How to add new line in Ruby? In Ruby, newlines (line breaks) play a crucial role in formatting and separating your code. Whether you're crafting clear error messages or building readable output, knowing how to add newlines is essential. Here's a breakdown of various methods you can use: 1. The Almighty `puts`:The built-in `puts 2 min read Like