jeudi 29 décembre 2016

Define article owner ( Couldn't find Article without an ID)

I'm trying to define an article owner, for that I have to independent resources, which are not nested in each other (user, article).

Each article has an user_id attribute which corresponds to the id of the user who created the article.

Now I'm trying to match both so I can create an article owner.

This is how I'm trying to do it:

Articles_controller.rb

def show
      @article = Article.find(params[:id])
      @user_id = Article.find(params[:user_id])
      @user= User.find_by(id: user_id)
end

Aucun commentaire:

Enregistrer un commentaire