Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Friendly_id, pretty URL naming sequence and breaking find_by method

friendly_id find_by pretty_url

  • Please log in to reply
1 reply to this topic

#1 andrewliu

andrewliu

    Signalman

  • Members
  • 17 posts

Posted 17 October 2013 - 06:08 PM

I'm trying to create a URL with name-city-#, but I'm getting 
    name-name-city
    name-name-city--1
    name-name-city--2
    ... and so on
from my slugged column database.
 
I have this in my model:
      extend FriendlyId
      friendly_id :slug_candidates, :use => [:slugged, :history]
    
      def slug_candidates
        [
          :name,
          [:name, :city]
        ]
      end 
 
Which I believe is correct and should give me the right names?
 
-------------
 
Also, before friendly_id I would be able to use `find_by_business_id(@biz)`, but because of the friendly_id, I'm getting an error:
 
I have this in my controller:
    @biz = Business.find(params[:id]) 
    @bizphoto = BusinessPhoto.find_by_business_id(@biz)
and in my view:
    <%= image_tag @bizphoto.bizurl_url(:avatar) %>
I'm getting the error of `undefined method 'bizurl_url' for nil`, and I think its because of the `find_by` method, but I'm not sure what the correct ruby syntax is when using slug URLs now.
 
 
Thanks


#2 andrewliu

andrewliu

    Signalman

  • Members
  • 17 posts

Posted 18 October 2013 - 04:49 AM

Nevermind, I realized I was using trying to implement a more recent version of friendly-id that was not compatible with my current rails app






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users