<%= link_to categorization_path(categorization: :adventure) do %>
<span class="glyphicon glyphicon-picture", id="challenge-category"></span>
<% end %>
# There are other categories such as health, work, wacky, etc
的routes.rb僅在控制器動作中顯示具有相同屬性的對象?
get ":categorization", to: "pages#home", as: 'categorization'
此時如果上述link_to
用戶點擊我想只顯示與categorization: adventure
屬性的挑戰。
我需要在pages#home
中輸入什麼才能使這項工作成功?
pages_controller.rb
def home
@challenges = current_user.challenges.order("deadline ASC")
#How to only show one of the :categorization challenges if URL is root_path/:categorization?
end
challenge.rb
CATEGORIZATION = ['adventure', 'health', 'work', 'buy', 'wacky']
scope :adventure, -> { where(categorizations: 'Adventure') }
scope :health, -> { where(categorizations: 'health') }
scope :work, -> { where(categorizations: 'Work') }
scope :buy, -> { where(categorizations: 'Buy') }
scope :wacky, -> { where(categorizations: 'Wacky') }
scope :goal, -> { where(categories: 'Goal') }
scope :habit, -> { where(categories: 'Habit') }
「無不是一個符號」 是一個錯誤 –
你可以發佈 logger.debug的輸出PARAMS 到這一行動? –
'PG :: UndefinedColumn:錯誤:列挑戰..categorizations不存在 線1:...挑戰「在哪裏挑戰」。「user_id」= $ 1和「挑戰...」 –