friendly-id

Friendly_ID Ruby on Rails

扶醉桌前 提交于 2021-02-10 07:26:52
问题 The URL still shows the id and not the title even after using slug. Code as follows index.html.erb <title>Blog!</title> <h1>List of the Posts</h1> <% @posts.each do |post| %> <%= link_to post.title,:id => post.slug%> <p><%= post.content %></p> <%= link_to "Edit",edit_post_path(post) %> | <%= link_to "Delete",post,:confirm=>"Are you sure ?",:method=>:delete %> <hr /> <% end %> <p><%= link_to "Add a New Post",new_post_path %></p> posts_controller.rb class PostsController < ApplicationController

How to use the slug from Friendly_id in a nested route?

时光毁灭记忆、已成空白 提交于 2021-02-08 05:38:15
问题 I am having a hard time making the slug from Friendly_id in a nested route when editing and creating? the routes look great for show. http://0.0.0.0:3000/test/tester2 This is the URL I am getting when i try to edit tester2 is: http://0.0.0.0:3000/2/tester2/edit What i would like to see is: http://0.0.0.0:3000/test/tester2/edit Here is my code. team.rb class Team < ActiveRecord::Base extend FriendlyId friendly_id :name, use: :slugged has_many :videos ... end video.rb class Video < ActiveRecord

Rails friendly_id with arabic slug

主宰稳场 提交于 2021-01-28 03:05:43
问题 My question is closely related to this one Rails friendly id with non-Latin characters. Following the suggested answer there, I implemented a little bit different solution (I know, it's primitive, but I just want to make sure it works before adding complex behavior). In my user model I have: extend FriendlyId friendly_id :slug_candidates, :use => [:slugged] def slug_candidates [ [:first_name, :last_name], [:first_name, :last_name, :uid] ] end def should_generate_new_friendly_id? first_name

Breadcrumbs list in ActiveAdmin shows wrong name when using friendly_id

☆樱花仙子☆ 提交于 2021-01-01 07:14:17
问题 I have a model named Company that has code . The column is used for friendly_id . class Company < ActiveRecord::Base extend FriendlyId friendly_id :code, use: :slugged end ActiveAdmin doesn't recognize friendly_id , so that I had to override find_resource method like this: ActiveAdmin.register Company do controller do def find_resource scoped_collection.friendly.find(params[:id]) end end end With this code I can edit the model attributes by ActiveAdmin, but breadcrumbs list in edit page shows

Breadcrumbs list in ActiveAdmin shows wrong name when using friendly_id

妖精的绣舞 提交于 2021-01-01 07:13:52
问题 I have a model named Company that has code . The column is used for friendly_id . class Company < ActiveRecord::Base extend FriendlyId friendly_id :code, use: :slugged end ActiveAdmin doesn't recognize friendly_id , so that I had to override find_resource method like this: ActiveAdmin.register Company do controller do def find_resource scoped_collection.friendly.find(params[:id]) end end end With this code I can edit the model attributes by ActiveAdmin, but breadcrumbs list in edit page shows

Nested form sends :id instead of friendly_id in POST request

久未见 提交于 2020-07-22 21:31:12
问题 routes.rb: resources :courses, path: '' do resources :students do resources :awards end end students/show.html.erb <%= form_for [@course, @student, @award] do |f| %> <div class="field"> <%= f.label :ticket %><br> <%= f.text_field :ticket %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> models/student.rb belongs_to :course has_many :awards, dependent: :destroy extend FriendlyId friendly_id :uuid, use: [ :slugged, :finders ] controllers/students_controller.rb before_action :set

How to redirect old urls to new friendly_id generated urls in rails app?

本小妞迷上赌 提交于 2020-01-17 08:55:29
问题 I prettified my urls using friendy_id . My old url used look like below: localhost:3000/search?category_id=208 Now it looks like this: localhost:3000/search?category_id=metal-processing-and-machine-tool My controller is this: def search_equipments begin if (params.keys & ['category_id', 'sub_category', 'manufacturer', 'country', 'state', 'keyword']).present? if params[:category_id].present? @category = Category.active.friendly.find_by_friendly_id params[:category_id] else @category = Category

using an associated field name in slug_candidates in friendly_id

烂漫一生 提交于 2020-01-15 03:09:08
问题 Is it possible to use a association in my slug_candidates method? for example, where my model belongs_to :car def slug_candidates [ [car.owner, :horsepower, "horsepower"], [car.owner, car.nickname, :horsepower, "horsepower"] ] end right now it returns NoMethodError: undefined method `owner' for nil:NilClass 回答1: I assume this is a method defined in an ActiveRecord model. It's because one of the records you are using does not have a car (ie. it is nil ). So when you do car.owner on that

Using Rails 5, how can I make FriendlyId append a -“count+1” to duplicate slugs instead of a UUID?

a 夏天 提交于 2020-01-06 07:25:35
问题 Apparently FriendlyId has changed it's previously default method of appending a numeric sequence to duplicate slugs (which is what I want) to now use UUID: Previous versions of FriendlyId appended a numeric sequence to make slugs unique, but this was removed to simplify using FriendlyId in concurrent code. This functionality is not something I'm interested in at this time and would much prefer to have the original method that results in a cleaner URL. I found a similar question where someone

Rails 4 Blog /:year/:month/:title with clean routing

白昼怎懂夜的黑 提交于 2020-01-03 17:20:33
问题 In Rails 4 is there another cleaner way to achieve routes, such as: /blog/2014/8/blog-post-title /blog/2014/8 /blog/2014 /blog/2014/8/tags/tag-1,tag-2/page/4 /blog/new OR /blog_posts/new I've tried the following using FriendlyId (as well as acts-as-taggable for tag param and kaminari for page param): blog_post.rb extend FriendlyId friendly_id :slug_candidates, use: [:slugged, :finders] def to_param "#{year}/#{month}/#{title.parameterize}" end def slug_candidates [ :title, [:title, :month,