I have a model :folder that belongs to :user and takes a user_id. A user can create as many folders as they want, and the homepage renders all folders that have the user_id of the current user. However, using this code on the homepage:
<ol class="folders-vertical">
<%= render @folders %>
</ol>
with this instance variable in the homepage controller:
@folders = current_user.folders
It also renders the :folder model itself. So, each user's first folder is the :folder model instead of the actual first folder they create. How can I avoid rendering this?
您可以使用如下形式:
@folders = Folder.where(user_id: current_user.id).drop(1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.