Rails : Using jquery tokeninput (railscast #258) to create new entries

后端 未结 2 1111
-上瘾入骨i
-上瘾入骨i 2020-12-30 14:33

I have successfully been able to implement the addition of new artist entries which was not included in Ryan Bates railscast #258 http://railscasts.com/episodes/258-token-fi

2条回答
  •  情书的邮戳
    2020-12-30 15:21

    if you're using some authentication solution like devise, clearance or authlogic, you probably already have current_user method. Therefore add a column user_id:integer to the Artist model and do the following:

    #User model
    has_many :artists
    
    #Artist model
    belongs_to :user
    
    #Artists controller
    def index
        @artists = current_user.artists.where("name like ?", "%#{params[:q]}%") #this answers your question!
        ... blah blah
    end
    

    And of course do not forget to set the user_id column when you create an artist.

提交回复
热议问题