I'm using the friendly_id gem for modifying my urls. But i have a problem with my likes system.
For the use of friendly_id i change my controller:
@software = Software.find(params[:id])
to
@software = Software.friendly.find(params[:id])
So my like.js do not recognize the id of my model. Here is the error:
ActionView::Template::Error (undefined method `id' for nil:NilClass):
1: $('#like-icon-software-<%= @software.id.to_s %>').
2: html('<%= j render "softwares/like_icon", {is_liked: @is_liked, software: @software} %>');
Thank you for your help and sorry for my english ..
EDIT 1:
I get in the params :
Processing by LikesController#create as JS Parameters: {"software_id"=>"Odoo"}
instead of
Processing by LikesController#create as JS Parameters: {"software_id"=>"1"}
without friendly_id.
models/software.rb
extend FriendlyId
friendly_id :title, use: [:slugged, :finders]
def is_liked user
Like.find_by(user_id: user.id, software_id: id)
end
How to continue to receive the id and not the "slug" ?