I'm trying to develop an application in Ruby on Rails 4.0 (older versions of this incredible structure have already been used), and I have some problems.
I installed the FriendlyID gem and I think that everything is in order, but I get errors when I try to test my application.
If I go to http://0.0.0.0:3000/categories/1 , this will work. But when I click on βeditβ on this page or just go to http://0.0.0.0:3000/categories/electronics {000/categories/electronics (this is a broken category name with identifier 1), I get the following error:
Couldn't find Category with id=electronics
Category Model:
class Category < ActiveRecord::Base extend FriendlyId friendly_id :name, use: :slugged
Controller categories:
(generated by scaffold for testing purposes)
class CategoriesController < ApplicationController before_action :set_category, only: [:show, :edit, :update, :destroy]
Migration: ##
(I added friendlyId after creating the Category table, but I think everything is fine)
class AddColumnToCategory < ActiveRecord::Migration def change add_column :categories, :slug, :string add_index :categories, :slug, unique: true end end
Routes:
resources :categories
I hope you help me. What am I doing wrong in Rails 4.0?
ruby ruby-on-rails ruby-on-rails-4 friendly-id
Paladini
source share