Having trouble understanding how using links_to filter content within the same controller in the rails view works. My code is below:
# index.html.erb (link nav area)
<nav> <%= link_to 'Daily Monitoring', root_path(:category => "dailymonitoring") %> <%= link_to 'Smoke Tests', root_path(:category => "smoketests") %> </nav>
# index.html.erb (cont.)
<ul id="results"> <% if @reportlinks == "dailymonitoring" %> # dailymonitoring content <% elsif @reportlinks == "smoketests" %> # smoketests content <% end %> <!-- end conditional --> </ul>
if params[:category] @reportlinks = Report.where(:category => params[:category]) else @reportlinks = Report.all end
# model (report.rb)
class Report include ActiveModel::Model attr_accessor :reports, :smokereports belongs_to :reports, :smokereports, :reportlinks end
The error I'm getting is undefined method `belongs_to' for Report:Class and a < top (required) > error. There's no database involved. I'm just trying to make it known that I want to click on any of the links and that filters only the block of content within that if/else statement.
Do I need to create a new controller for the if/else statement to work? Please let me know if more code is needed to get a better understanding. Thanks.