Trouble locating and displaying list of records from a relationship model in Rails app

前端 未结 3 584
终归单人心
终归单人心 2021-01-15 01:16

I have a relationship model that tracks customers (users) of shops in a has_many :through association. I\'m having trouble with my ShopsController

3条回答
  •  终归单人心
    2021-01-15 02:12

    Your relationships method in your controller is all over the place.

    You're trying to find relationshipS using a find by id with a non-existent params[:relationship_id] which is causing the error you're seeing.

    You're then setting @users to be all the relationships for the @shop.

    Then you're rendering a template show_relationships but you refer later to a relationships/show template.

    Additionally in the shop model you're calling create on relationships with just a user id whereas you'd expect to be passing in some attributes for the relationship.

    It looks like this code has got messier and messier as you've tried to solve the problem. To be perfectly honest I'd go back to the beginning and start again.

提交回复
热议问题