ruby on rails - How to have user_id inserted in a different table (no, not foregin key) -
this table:
load (0.4ms) select "likes".* "likes" +----+------------+-------------------------+-------------------------+---------+ | id | article_id | created_at | updated_at | user_id | +----+------------+-------------------------+-------------------------+---------+ | 1 | 1 | 2014-03-24 19:07:59 utc | 2014-03-24 19:07:59 utc | | | 2 | 2 | 2014-03-24 19:18:59 utc | 2014-03-24 19:18:59 utc | | | 3 | 4 | 2014-03-24 19:19:14 utc | 2014-03-24 19:19:14 utc | | | 4 | 9 | 2014-03-24 19:47:36 utc | 2014-03-24 19:47:36 utc | | +----+------------+-------------------------+-------------------------+---------+ 4 rows in set
as can see, it's not filling in user_id information when article.
how fill in information in table above?
this method in articlecontroller:
def like_vote @article = article.find(params[:id]) @article.likes.create redirect_to(article_path) end
i'm kind of confused on figuring out how insert user_id in aforementioned method so, table stores user_id.
help?
in case needed: view
<td><%= pluralize(article.likes.count, "like") %></td> <td><%= button_to '+1', "/articles/#{article.id}/user/#{current_user.id}/like_vote", method: :post %></td>
you should set user_id
, example:
@article.likes.create(user_id: current_user.id)
Comments
Post a Comment