0
Guys, I’m developing a system in ROR and I have a news table in the bank, and there is a column featured and every time the admin register another news as featured even if there is already one in the bank, the controller has to remove the one that was already highlighted and put this new one. NOTE: The highlighted field is Boolean so it will only change from "true" to "false".
Controller
def create
# @notice = Notice.new(notice_params)
featured = params[:notice][:featured]
category = params[:notice][:category_id]
user = current_user.secretary.prefecture.county_id
if featured = 1
@notice = Notice.where(county_id: user, category_id: category, featured: true)
if @notice.present?
@notice = Notice.find(@notice.id).update(featured: false) rescue nil
end
end
end
and what is your doubt? what is wrong?
– Ricardo Pontual
Hello Ricardo, thank you so much for asking, but I’ve already solved. I wanted to feature a headline and if there ever was one featured in the same category it would remove the headline from the one that already existed and add the new headline.
– Maikon Douglas