简体   繁体   中英

Overriding _path rails helper method

There is a column in the database called photo_path in the post table and in my view file where i display all the posts i have:

<% if post.photo_path != 0 %>

That is, if there is no photo for that particular post. But the problem is, i'm getting a conflict with the rails helper method. It's converting my code to

<%= if /uploads/post/photo_path/1/0 != 0 %>

How do i make it use the database column photo_path and not the photo_path helper method?

!= 0 is very bad syntax, use instead ".blank?" or ".present?" methods.

Your post model have associated with photos model? If yes, why do you need this column in db? Remove from db this column or rename it to human name. Maybe it simpler user this? :

<% if post.photos.present? %>
.......

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM