0

Does anybody have any good resouces to wrap my head around the concept of adding different parts of one model to the index on another model.

Ex. I would like to add upvote(like) to each post on the index page.

Ex. I would like to add the comment form attached to each post on the index page.

I can do all this on the show page, but can I do it on the index page?

CC Evans
  • 39
  • 7
  • Show us how you did it on the show page, how you'd do it on the index page is typically just applying that same logic repeatedly for each instance on the index page. – Nick Veys Jan 04 '15 at 03:08
  • @NickVeys Here is a link to the details http://stackoverflow.com/questions/27752123/trying-to-add-a-partial-form-to-my-index-page-how-do-i-pass-multiple-variables. – CC Evans Jan 04 '15 at 03:54

1 Answers1

1

If you would like to add an up vote link on the index page, all you need to do is link_to the update action, setting the method as put and providing the data required for the update. More here.

As for the comments section, I am not sure exactly how your models are set up but if you do something along the lines of this in controller:

def index
  @models = Model.all #whatever you're showing on your index page

  @comments = Model.comments.all
  @comment = Model.comments.new
end

where Model is the name of your model, which has a has_many :comments association.

In your view, you can just list the @comments and set up a form for a new @comment.

Community
  • 1
  • 1
Aventuris
  • 630
  • 5
  • 21
  • Here is a link to the details http://stackoverflow.com/questions/27752123/trying-to-add-a-partial-form-to-my-index-page-how-do-i-pass-multiple-variables. – CC Evans Jan 04 '15 at 03:54
  • Do you have a specific question about the implementation? From your other link it seems that your project doesn't quite follow RESTful architecture, I recommend that you read up on it. Generally speaking, except for in some rare circumstances, you should not need extra actions in your controller besides the basic CRUD actions. – Aventuris Jan 04 '15 at 04:33