
06.10.2025
Integrating Angular with Rails: Step-by-Step Guide

Dariusz Michalski
CEO
Learn how to integrate dynamic frontends with efficient backends using Angular and Rails, tailored for Swiss businesses' unique needs.
Integrating Angular with Rails combines Angular's dynamic frontend capabilities with Rails' efficient API backend. This setup is especially relevant for Swiss businesses, supporting multilingual interfaces, Swiss-specific formats (like CHF 1'234.56), and robust data handling. Here's why and how to do it:
Why Combine Angular and Rails?
Angular excels at building responsive, interactive frontends with strong TypeScript support. Rails simplifies API development with its "convention over configuration" approach, making backend processes predictable and efficient. Together, they create a clear division of responsibilities, allowing teams to work independently while enabling real-time features like live updates and notifications.
Applications for Swiss Companies
This stack is widely used in Switzerland for:
E-commerce: Real-time inventory updates, secure payment processing, and multilingual support.
Finance: Interactive dashboards and secure transaction handling.
SaaS: Scalable tools for local and global markets.
Enterprise Tools: Internal systems for sectors like manufacturing and healthcare.
Key Setup Requirements
To start, you’ll need:
Backend: Ruby on Rails (v3.0+), PostgreSQL (v13+), and
rack-corsfor API communication.Frontend: Angular CLI (v16+), Node.js (v16+), and locale settings for Swiss formats (e.g.,
de-CH,fr-CH).Swiss Formatting: Use tools like
money-railsfor CHF currency,DecimalPipein Angular for number formatting, and proper locale files for multilingual support.
Implementation Highlights
Rails API: Build a lightweight API-first backend using Rails'
--apiflag. Configure database and CORS for communication with Angular.Angular Frontend: Use Angular CLI to create a frontend, set up a proxy for API requests, and ensure Swiss-specific formatting for numbers, dates, and currencies.
CRUD Operations: Develop endpoints in Rails and corresponding Angular components for creating, reading, updating, and deleting data.
Testing and Deployment: Test APIs and frontend thoroughly, focusing on Swiss formatting and multilingual support. Deploy by serving Angular files through Rails.
This integration is ideal for Swiss businesses aiming to modernize their web applications while meeting local standards for currency, language, and data handling.
Build a FullStack CRUD App (Rails + Angular) - Beginner Tutorial
Setup Requirements and Development Environment
Getting your development environment ready for integrating Angular with Rails involves setting up essential tools and ensuring locale-specific configurations. For developers in Switzerland, it's particularly important to account for Swiss-specific number formatting, currency display, and date-handling standards.
Tools and Software You Need
To start, you'll need a mix of backend and frontend tools:
Ruby and Rails: Install Ruby (version 3.0 or newer) using a version manager like
rbenvorRVM. Once Ruby is set up, install Rails by runninggem install railsin your terminal.Node.js and npm: These power Angular's frontend ecosystem. Install Node.js (v16 or newer), which includes npm. Verify the installation by running
node --versionandnpm --version.Angular CLI: Simplify Angular project management by installing Angular CLI globally with
npm install -g @angular/cli. Ensure you're using version 16 or newer for compatibility with modern Rails APIs.Database: PostgreSQL is a great choice for Swiss projects needing robust data handling. Install version 13 or newer to benefit from locale-specific support for formatting Swiss francs (e.g., CHF 1'234.56).
Code Editor: Use Visual Studio Code with extensions like "Ruby" by Peng Lv and "Angular Language Service" for syntax highlighting, debugging, and intelligent code suggestions that align with Swiss formatting.
With these tools in place, you're ready to configure your environment for smooth integration.
Environment Configuration Steps
Setting up your environment properly ensures everything runs seamlessly:
Version Management: To avoid conflicts, use
rbenvfor Ruby andnvmfor Node.js. Addeval "$(rbenv init -)"to your shell profile to automate Ruby version selection.Environment Variables: Store sensitive data like database credentials and API keys in a
.envfile at your Rails project root. For Swiss projects, include locale settings such asLOCALE=de-CHorLOCALE=fr-CH. Make sure this file stays out of version control.Database Configuration: Update your Rails
database.ymlfile to include encoding and locale settings. For Swiss applications, useencoding: unicodeand set the locale tode_CH.UTF-8orfr_CH.UTF-8for proper handling of Swiss formats.CORS Setup: Add the
rack-corsgem to your Gemfile and runbundle install. This is essential since Angular typically operates on port 4200, while Rails uses port 3000.SSL Certificates: Use OpenSSL to generate self-signed certificates for testing secure features like payment integrations, which are common in Swiss applications.
Swiss Format Standards for Developers
Swiss-specific settings are crucial for providing a seamless user experience. Here's how you can align your application with these standards:
Number Formatting: In Rails, use the
number_with_delimiterhelper to display numbers like 1'234.56 (apostrophe for thousands, dot for decimals). For Angular, configure the locale tode-CHorfr-CHand use theDecimalPipe.Currency Handling: Set up the
money-railsgem in Rails with CHF as the default currency. Ensure values display as "CHF 1'000.00". In Angular, use theCurrencyPipewith the 'de-CH' locale for consistent formatting.Date and Time: Rails should use
%d.%m.%Yfor dates in locale files, while Angular apps should register Swiss locales (de-CHorfr-CH) inapp.module.tsand apply theDatePipefor formatting.Locale Files: For multilingual support, create locale files in Rails (
de-CH.yml,fr-CH.yml,it-CH.yml) with Swiss-specific formats. Angular should have corresponding i18n translation files.Validation Patterns: Ensure Rails validators support Swiss postal codes (4 digits), phone numbers (+41 format), and VAT numbers (CHE format). Match these patterns in Angular forms for a consistent experience.
Building the Rails Backend
With your development environment set up, it's time to build the Rails API that will provide data to your Angular frontend. This backend will handle server-side logic, database operations, and API endpoints for your Angular application to consume.
Creating a Rails API Application
Start by generating a new Rails API using this command:
rails new my_angular_rails_api --api --database=postgresql
The --api flag sets up a lightweight Rails app without views, helpers, or assets, keeping it focused on API functionality. The --database=postgresql option configures PostgreSQL as the database, which works well for Swiss locale formatting.
Navigate into the project directory:
cd my_angular_rails_api
You’ll notice the structure is streamlined for handling JSON responses. Next, open the Gemfile and add gems tailored for Swiss applications. Include:
gem 'money-rails'for proper Swiss franc (CHF) currency handling.gem 'i18n'for multilingual support.
Run bundle install to install these dependencies.
Now, generate a product model using:
rails generate model Product name:string price:decimal description:text
Before running the migration, edit it to set the price field with a precision of 8 and a scale of 2. This ensures accurate calculations for Swiss franc values.
Once the API structure is ready, configure cross-origin requests (CORS) to enable smooth communication with your Angular frontend.
Setting Up CORS for Angular
To handle cross-origin requests, add the rack-cors gem if it’s not already included. Then, run:
bundle install
Modify the config/initializers/cors.rb file to allow requests from your Angular development server (http://localhost:4200). Configure it to permit:
Specific HTTP methods: GET, POST, PUT, PATCH, DELETE, and OPTIONS.
Required headers: 'Accept', 'Authorization', 'Content-Type', 'Origin', and 'X-Requested-With'.
For Swiss-specific needs, include headers like 'Accept-Language' and 'X-Locale'. These allow your Angular frontend to send locale data, enabling the Rails backend to return properly formatted Swiss responses.
To test your CORS setup, start the Rails server:
rails server
Then, try a simple GET request in your browser’s developer console:
fetch('http://localhost:3000/api/products')
If everything is configured correctly, you won’t encounter any cross-origin errors.
Database Configuration and Sample Data
Now, configure your database to handle Swiss formats. Update the config/database.yml file under the development section to include:
encoding: unicodelocale: de_CH.UTF-8
This ensures proper handling of Swiss number formats and currency symbols.
Create and migrate the PostgreSQL database, then populate it with sample data in db/seeds.rb. Use realistic Swiss prices (e.g., 1'299.90) and include product names in multiple Swiss languages like German, French, and Italian to test your internationalisation setup.
Add a config/initializers/money.rb file with the following configuration:
This ensures Swiss currency formatting uses apostrophes for thousand separators.
Next, generate a controller to serve your product data:
rails generate controller Api::Products
This creates a namespaced controller under the Api module, keeping your endpoints well-organised. Implement basic CRUD actions in the controller, ensuring JSON responses follow Swiss standards.
Finally, seed the database, start the Rails server, and test your API endpoint at:
http://localhost:3000/api/products
Your Rails backend is now ready to support the Angular application in the next phase of integration.
Creating the Angular Frontend
Now that your Rails API backend is up and running, it’s time to build the Angular frontend to interact with those API endpoints. Angular is a fantastic choice for creating dynamic web applications, and when tailored to Swiss development needs, it becomes even more effective.
Starting a New Angular Project
First, open a terminal and navigate to your project directory. Use the Angular CLI to create a new Angular application:
ng new my-angular-frontend
When prompted, select Yes for routing and choose CSS as the stylesheet format. These options are ideal for Swiss business projects that often require clean styling and multilingual navigation.
Next, move into the newly created Angular project folder:
cd my-angular-frontend
To support API communication and localisation, install the necessary packages:
ng add @angular/localize
Now, open the angular.json file and configure it for Swiss locale support. Under the build section, add locales for German (de-CH), French (fr-CH), and Italian (it-CH). This ensures your app is ready to handle Switzerland’s multilingual environment right from the start.
Create a service to manage API communication:
ng generate service services/product
This service will handle all HTTP requests to your Rails backend. In the generated product.service.ts file, import the HttpClient module and use the Injectable decorator to set up the service.
Finally, start the Angular development server to confirm everything is working:
ng serve
Once the server is running, you can access the app in your browser at http://localhost:4200. With the basic setup complete, the next step is to configure a proxy for seamless communication between the Angular frontend and Rails backend.
API Proxy Setup and Configuration
To avoid cross-origin issues during development, Angular's built-in proxy can forward API requests to your Rails backend. Create a proxy.conf.json file in the root of your Angular project and add the following configuration:
This setup directs all requests starting with /api/ to your Rails backend running on port 3000. The logLevel: "debug" option is helpful for troubleshooting any connectivity issues during development.
Next, update the angular.json file to use this proxy. Under the serve section in options, add:
"proxyConfig": "proxy.conf.json"
Restart the Angular development server:
ng serve
To test the proxy, open your browser's developer console and make a request:
fetch('/api/products')
If everything is configured correctly, this request will reach your Rails backend without triggering any CORS errors. For Swiss-specific API endpoints, you can extend the proxy configuration to include routes like /api/de-ch/products.
Connecting Angular to Rails API
With the proxy in place, you can now implement methods in your Angular service to interact with the Rails API. Open src/app/services/product.service.ts and define methods for GET, POST, PUT, and DELETE requests using Angular's HttpClient.
To ensure proper handling of Swiss-specific data, create an interface for your product model in src/app/models/product.interface.ts. Include fields like name, price, and description, and ensure the price field is formatted for Swiss standards. For example, use Angular's DecimalPipe to display prices in the format CHF 1'299.90.
Next, generate a component to display products:
ng generate component components/product-list
In the new component, inject the product service and add methods to fetch and display products. Use Angular's async pipe in the component template to handle HTTP observables efficiently. Format prices and dates to align with Swiss conventions, ensuring a user-friendly experience.
Update the app.module.ts file to include the HttpClientModule and register Swiss locales (de-CH, fr-CH, it-CH). This ensures consistent formatting for dates, numbers, and currencies throughout your application.
Finally, implement error handling in your service for scenarios like network timeouts or server errors. Swiss users expect reliable applications, so make sure to include clear, user-friendly error messages in the appropriate language.
With these steps completed, your Angular frontend is now fully integrated with the Rails backend, offering a seamless and localised experience for Swiss users.
Building CRUD Operations
After successfully integrating Angular with Rails, the next step is to implement CRUD operations for managing products. These operations should be tailored to meet the specific needs of Swiss businesses.
Rails API Endpoints for CRUD
Start by generating a Rails controller for the product model:
This creates a namespaced controller for API endpoints. Next, open app/controllers/api/products_controller.rb and define the standard CRUD actions.
The index action retrieves all products and returns them as JSON:
The show action fetches a specific product by its ID:
To allow the creation of new products, implement the create action with parameter validation:
The update action modifies an existing product:
Finally, the destroy action deletes a product:
In config/routes.rb, map these actions to routes:
This single line generates all necessary routes: GET /api/products (index), GET /api/products/:id (show), POST /api/products (create), PATCH /api/products/:id (update), and DELETE /api/products/:id (destroy).
For compatibility with Angular, bypass CSRF protection in your API controller. Create a base controller at app/controllers/api/application_controller.rb:
Update the ProductsController to inherit from this base class. With this, the backend is ready to handle CRUD operations.
Angular Components for Data Management
Now, build Angular components to interact with the Rails API. Start by updating the product service with methods for CRUD actions. Open src/app/services/product.service.ts and add the following:
Next, generate a product management component:
In the component's TypeScript file, implement methods to handle data operations and error handling:
Design a user-friendly template with forms for creating and editing products, and a table for displaying the product list. This completes the front-end integration with the Rails API.
Showing Data in Swiss Formats
To ensure the data aligns with Swiss standards, update your Angular app to display prices, dates, and numbers in the correct format. Start by registering Swiss locales in app.module.ts:
Use Angular's currency pipe to format prices:
This formats prices as CHF 1'299.50, including the apostrophe as a thousand separator and two decimal places.
For dates, apply the date pipe:
This displays dates in the 06.10.2025 format.
When handling large numbers, use the decimal pipe:
This ensures numbers like 1'000 are correctly formatted with an apostrophe as the separator.
For multilingual applications, add support for German, French, and Italian. Use Angular's i18n package and translation files for text localisation, ensuring validation messages and labels are displayed in the user's preferred language.
With these steps, your Angular-Rails integration now provides a seamless and user-friendly system for managing data, fully aligned with Swiss business standards.
Testing and Deployment
Once your CRUD operations are ready, testing ensures everything works as intended before launching. This step helps catch issues early and ensures Swiss formatting requirements are correctly applied across the system.
Testing Your Integration
Begin with unit tests for your Rails API endpoints. These tests, stored in the spec/controllers directory, confirm that each CRUD operation handles data as expected. For example, verify that product prices are displayed in Swiss francs and dates follow the DD.MM.YYYY format:
For Angular components, write integration tests to ensure smooth interaction between the frontend and backend. Use Angular's testing tools to simulate user actions and validate data presentation in Swiss formats:
End-to-end testing checks the entire user experience. Tools like Cypress or Protractor are great for automating browser interactions. Test scenarios such as adding a product priced at CHF 2'500.00 and verifying that it displays correctly in the product list.
Run your Rails tests with bundle exec rspec and Angular tests with ng test. Both test suites should pass consistently before moving forward.
Fixing Common Problems
Once basic functionality is verified, address potential integration issues:
CORS Errors: These occur when Angular (running on
http://localhost:4200) tries to communicate with Rails (running onhttp://localhost:3000). If you see "Access to XMLHttpRequest blocked by CORS policy" in your browser console, your Rails app needs to allow requests from Angular's origin.Preflight Request Failures: OPTIONS requests, sent before PUT, DELETE, or POST requests with JSON, may fail. Add this method to your API controllers to handle OPTIONS requests:
API Endpoint Issues: Routing conflicts or incorrect URL patterns can cause errors. Use
rails routes | grep apito ensure your API routes match Angular's service calls.Data Formatting Conflicts: Rails might return data in a format Angular can't process. Make sure your controllers return consistent JSON structures and handle null values properly:
Use browser developer tools to inspect network requests. The Network tab can reveal issues with request headers, response codes, or payloads.
Local Deployment and Testing
With issues resolved, deploy your setup locally to simulate a production environment. Start by building your Angular app for production:
This generates production files in the dist directory. Configure Rails to serve these files by updating config/routes.rb:
Add a fallback method in your ApplicationController:
Copy Angular's built files to Rails' public directory:
Start the Rails server with rails server and open http://localhost:3000. Test the integration by creating a product with a price of CHF 3'450.75. Confirm that it displays as CHF 3'450.75 and that dates use the DD.MM.YYYY format.
Monitor Rails logs with tail -f log/development.log to catch backend errors. Pay attention to response times and database performance, especially with larger datasets.
Finally, test your application in multiple browsers, including Chrome, Firefox, and Safari, to ensure consistent behaviour. Different browsers may handle CORS and JavaScript differently, so thorough testing across environments is essential.
Your application should now be ready for production deployment, with Swiss formatting requirements fully implemented and tested.
Summary and Next Steps
You've successfully developed an Angular-Rails integration tailored to Swiss standards, laying the groundwork for modern, efficient web applications. From setting up the environment to deploying the final product, this integration showcases how Angular and Rails can work together to deliver scalable and maintainable solutions.
Integration Process Overview
The journey began with establishing a development environment aligned with Swiss requirements, advancing step by step through CRUD functionality and integration. The Rails API handled backend endpoints, while the Angular frontend was configured with proxy settings to ensure smooth communication between the two.
CRUD operations became the backbone of the application, allowing users to create, read, update, and delete data. These operations were implemented with Swiss-specific formatting, such as currency in CHF, dates in the DD.MM.YYYY format, and local number conventions. Rigorous testing - spanning unit, integration, and end-to-end tests - ensured the application performed reliably. A local deployment mimicked production conditions, fine-tuning the user experience for real-world scenarios.
This structured approach not only simplifies the development process but also offers practical advantages for Swiss businesses.
Advantages for Swiss Companies
This integration framework offers clear benefits to Swiss companies. Thanks to its modular design, the architecture supports future growth, making it easier to expand into mobile apps or add new web interfaces without reworking the core system.
The localisation features are particularly valuable for businesses operating across Switzerland's multilingual regions. Angular's internationalisation tools, combined with Rails' ability to format data appropriately, enable seamless language switching while preserving consistent business logic. Additionally, the combination of Rails' efficient database management and Angular's fast client-side rendering delivers quicker page load times and a more dynamic user experience.
Lastly, the development process itself becomes more streamlined. Rails' "convention over configuration" philosophy and Angular's component-based design allow teams to build complex applications faster, reducing the time needed to bring new digital solutions to market. This efficiency can be a game-changer for companies looking to stay ahead in today's competitive landscape.
FAQs
What advantages does combining Angular with Rails offer Swiss businesses?
Integrating Angular with Rails offers Swiss businesses a versatile and efficient solution for building modern web applications. This pairing combines Rails' solid backend capabilities with Angular's dynamic and interactive frontend, making it an excellent choice for delivering smooth and engaging user experiences.
For companies in Switzerland, this tech stack proves especially useful in multilingual settings, where Angular's adaptability supports localisation needs, while Rails efficiently manages intricate data structures. Moreover, this combination aligns well with the demands of regulated sectors, providing a structured framework that meets Switzerland's rigorous standards for security and compliance.
How can I ensure my application supports Swiss-specific formats for currency, dates, and languages?
To ensure your application aligns with Swiss-specific formats, leverage locale-aware tools like JavaScript's Intl API using the fr-CH or de-CH locale. This guarantees accurate formatting for currency (e.g., CHF 1'234.56), dates (e.g., 31.12.2023), and numbers (e.g., 1'000,50). For handling multilingual requirements, consider integrating internationalisation libraries such as i18next or Rails' built-in I18n module. These tools make it easier to adapt text, date formats, and numeric displays to Swiss conventions.
Switzerland’s multilingual nature requires special attention. Ensure your application supports key languages like German, French, and Italian. Offering users a clear and simple way to switch between these languages significantly improves both usability and accessibility.
What are the main challenges when integrating Angular with Rails, and how can they be solved?
Integrating Angular with Rails can sometimes feel like juggling two different worlds. Challenges often pop up, like handling separate development environments, ensuring seamless API communication, or keeping the data flow consistent. Another tricky part? Making sure the versions of Angular and Rails you're using play nicely together.
To tackle these hurdles, start by decoupling Angular and Rails. Use RESTful APIs to bridge the gap and set up proper CORS policies to avoid cross-origin headaches. Tools like Webpacker can help streamline builds, ensuring your frontend and backend stay neatly separated. It's also a good idea to test compatibility regularly and fine-tune your build processes to keep everything running smoothly.


