rails
Install Ruby: Download and install the Ruby programming language from the official website (https://www.ruby-lang.org/en/). Follow the installation instructions specific to your operating system.
Install Rails: Once Ruby is installed, open a terminal or command prompt and run the following command to install Rails using the RubyGems package manager:
gem install rails
- Create a new Rails application: Use the following command to create a new Rails application:
rails new myapp
Replace "myapp" with the desired name of your application.
- Navigate to the application directory: Change to the application directory using the
cd
command:
cd myapp
- Start the Rails server: Start the Rails server using the following command:
rails server
By default, the server will run on http://localhost:3000.
- Generate a new controller: Use the following command to generate a new controller:
rails generate controller Welcome index
This will create a new controller called "Welcome" with an action called "index".
- Define a route: Open the
config/routes.rb
file and add the following line to define a route for the Welcome controller's index action:
get 'welcome/index'
Create a view: Create a new file called
index.html.erb
in theapp/views/welcome
directory. This file will contain the HTML code for your view.Add content to the view: Open the
index.html.erb
file and add the desired HTML content.Start the server and access the application: Start the Rails server using the
rails server
command. Open a web browser and navigate to http://localhost:3000/welcome/index to see the content of your view.
Note: This is a basic overview of setting up a Ruby on Rails application. There are many more concepts and features to explore in Rails development, such as models, databases, and routing. Consider referring to official Rails documentation and online tutorials for more in-depth explanations and examples.