I have the code:
<a href="http://<%= @app.url %>"><h1><%= @app.name %></h1></a>
in show.html.erb and it runs fine. However when I paste that code to newsfeed.html.erb, it gives the following error message:
NoMethodError in Reviews#newsfeed
undefined method `url' for nil:NilClass
From reading other similar questions I think I need to make a change to reviews_controller.rb. This is (I think) the relevant code in that file:
def newsfeed
@reviews = Review.all
end
And the relevant code in the main AppsController
require 'Review'
class AppsController < ApplicationController
...
def show
@app = App.find_by_name(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @app }
end
end
I believe the solution is to add some code below def newsfeed but I’m not sure what to add. Or maybe that’s not even the solution.
Thanks for any help!
@app is nil. In the show action you set it like so
But you forgot to add it to the newsfeed action!