FAQ Database Discussion Community


User path with username

ruby-on-rails,ruby,path,user,friendly-id
To show User's profile I used their id. In controller: @user = User.find(params[:id]) In routes: get ':id' => 'users#show' But now I try new way with username: get ':username' => 'users#show' #route @user = User.find_by(username: params[:username]) #controller And when I go to user's profile with /username I see error: undefined...

Ruby on Rails 4 - friendly_id with nested routed

ruby-on-rails,ruby-on-rails-4,friendly-id,nested-resources
I have a nested rout for toys and then toys will have reviews. The toys works fine with friendly_id but going to website.com/toys/toy-name/reviews/new brings up Couldn't find Toy without an ID My routes file looks like this resources :toys do resources :reviews, except: [:show, :index] end The reviews controller has...

Switch locale on current page rails

ruby-on-rails,ruby,friendly-id,globalize
i'm currently working on a project which has 2 different locals (nl/fr). We're facing this problem : How can I get the translated url for the current page when I display fr/nl button I'm currently working with friendly_id and globalize we've tried : = link_to "nl", params.merge(locale: "nl") = link_to...

Having a duplicate number sequence in slug using FriendlyId

ruby-on-rails,ruby,friendly-id
I'm using the gem 'friendly_id', '~> 5.0.0 and I just want to use the old behaviour which is appending a number sequence count in the slug instead of UUID. for example >> test-slug-2 >> test-slug-3 >> test-slug-4 I was able to make this using: config/initializers/slugged.rb module FriendlyId::Slugged def resolve_friendly_id_conflict(candidates) column...

Changing Friendly ID Default Column

ruby-on-rails,friendly-id
I'm trying to work out how to change the default column that Friendly Id generates the unique name to. Currently, it requires the table to have a column called slug, but I need to generate a unique email address for an organisation, and 'slug' is not a correct identifier. This...

Root with slug rails 4 routing

ruby-on-rails,ruby,friendly-url,friendly-id
Currently I'm using friendlyID gem and I just want to redirect my application to a root with slug if the user is authenticaated. url http://localhost:3000/companyABC/dashboard Here's my current code authenticated :employer do root to: redirect("/:slug/dashboard"), as: :employer_root end namespace :company, path: "/:slug" do resources :dashboard namespace :settings do resources :collaborators...

Change the unique generated title names of friendly-id using attribute of another table

ruby-on-rails,ruby,seo,friendly-url,friendly-id
I have a Company Model, and i am using friendly_id like this friendly_id :name, use: :slugged But since there can be many Company with the same name (different branches). I am trying to handle that case by using city attribute from the address of the Company. But the Company address...

Friendly id in nested model

ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.2,friendly-id
I'm using friendly_id to generate URLs on my rails application. I have to following model organization : Ad : class Ad < ActiveRecord::Base belongs_to :area ... Area : class Area < ActiveRecord::Base has_many :ads validates :name ... And the following function in Ad model to generate the URL for each...

Friendly with existing Rails 4 app: No change

ruby,ruby-on-rails-4,friendly-id
I have an existing app with devise running. User and log in and out etc. Thought I would like to get localhost:3000/users/15 changed to localhost:3000/users/ruby-boy so I have installed https://github.com/norman/friendly_id I have ran rails generate friendly_id but when I ran rails generate scaffold user name:string slug:string:uniq, it say I already...

friendly_id gem doesn't create slug

ruby-on-rails-4,ruby-2.0,friendly-id
gem "friendly_id", "~> 5.0.4" Model: class Topic < Activerecord::Base extend FriendlyId friendly_id :generated_slug, use: [:slugged, :history] def generated_slug title end end On save of the topic from the new action, the slug doesn't get created and on top of that, the URL goes to something like this: http://localhost:3000/topics/7 and the...

Is there a way that the :reserved_words option for models in FriendlyId gem does not overwrite the Rails defaults?

ruby-on-rails,friendly-id
I have the default friendly_id configuration in place in my project, which without comments looks like this: FriendlyId.defaults do |config| config.use :reserved config.reserved_words = %w(new edit index session login logout users admin stylesheets assets javascripts images) end And a model which has this configuration: EXCLUDED_SLUG_VALUES = %w(users articles authors topics...