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.
private
def product_params
params.require(:product).permit(:name, :price, :description, :category)
end
@Injectable({
providedIn: 'root'
})
export class ProductService {
private apiUrl = '/api/products';
constructor(private http: HttpClient) { }
getAllProducts(): Observable<any[]> {
return this.http.get<any[]>(this.apiUrl);
}
getProduct(id: number): Observable<any> {
return this.http.get<any>(${this.apiUrl}/${id}
);
}
createProduct(product: any): Observable<any> {
return this.http.post<any>(this.apiUrl, product);
}
updateProduct(id: number, product: any): Observable<any> {
return this.http.put<any>(${this.apiUrl}/${id}
, product);
}
deleteProduct(id: number): Observable<any> {
return this.http.delete<any>(${this.apiUrl}/${id}
);
}
}
constructor(private productService: ProductService) { }
ngOnInit(): void {
this.loadProducts();
}
loadProducts(): void {
this.productService.getAllProducts().subscribe({
next: (data) => this.products = data,
error: (error) => console.error('Error loading products:', error)
});
}
saveProduct(): void {
if (this.isEditing) {
this.productService.updateProduct(this.selectedProduct.id, this.selectedProduct).subscribe({
next: () => {
this.loadProducts();
this.resetForm();
},
error: (error) => console.error('Error updating product:', error)
});
} else {
this.productService.createProduct(this.selectedProduct).subscribe({
next: () => {
this.loadProducts();
this.resetForm();
},
error: (error) => console.error('Error creating product:', error)
});
}
}
deleteProduct(id: number): void {
this.productService.deleteProduct(id).subscribe({
next: () => this.loadProducts(),
error: (error) => console.error('Error deleting product:', error)
});
}
resetForm(): void {
this.selectedProduct = {};
this.isEditing = false;
}
}
registerLocaleData(localeDeCh, 'de-CH', localeDeChExtra);
});
});
Serve Angular app
get '*path', to: 'application#fallback_index_html', constraints: ->(request) do
!request.xhr? && request.format.html?
end
end