ruby on rails - How to fix NoMethodError in #show error? -
i'm trying access specific review through link:
<%= link_to "full review", review_path(review) %><
show.html.erb:
<%= @review.pro %>
reviews_controller.rb:
def show @review = review.find(params[:id]) end
i have column in review table named pro shown in migration file here:
class createreviews < activerecord::migration def change create_table :reviews |t| t.string :pro t.string :con t.string :advice t.string :date t.string :role t.string :company t.timestamps end end
end
the error is:
undefined method `pro' nil:nilclass extracted source (around line #1): 1: <%= @review.pro %>
even when include 'puts @review' in show method, nothing gets returned in rails console. advice on how fix this?
update when manually include review.find(1) in show method:
processing reviewscontroller#show html parameters: {"id"=>"1"} rendered reviews/show.html.erb within layouts/application (0.9ms) completed 500 internal server error in 3ms
actionview::template::error (undefined method pro' nil:nilclass): 1: <%= @review.pro %> app/views/reviews/show.html.erb:1:in
_app_views_reviews_show_html_erb___648582160945665650_70143359368840'
nil exceptions of hardest debug. have "follow nil" @sameera207 suggesting.
in controller, try
def show @review = review.find(params[:id]) logger.info "review: #{@review}" logger.info "review nil? #{@review.nil?}" end
if log/development.log
shows review nil?: true
you're not finding right record. params should show in log file, too.
Comments
Post a Comment