-3

I am not a newbie in rails so this is embarassing but I keep getting a nomethoderror I don't know what s happening.

this is the error

enter image description here

and this is my controller

enter image description here

  • 2
    Please read the [How to ask](http://stackoverflow.com/help/how-to-ask) document and put source code in plain text instead of images. – Aleksei Matiushkin Nov 23 '16 at 18:03
  • 1
    Please read "[mcve]", then remove the images and copy/paste the text of the message into the question, along with the _absolute minimum_ code that demonstrates the problem. [We can't reuse an image](http://stackoverflow.com/q/5508110/128421), nor can the search engines index them, which helps others find your question and solve their coding problem. – the Tin Man Nov 23 '16 at 18:57

3 Answers3

1

This happens when there's no matching method in the instance that you're accesing in this case, in this case if you look at the show action it only does the find_item and the find_item only returns a @post instance not an @item instance.

Just change @post to @item in the controller

neydroid
  • 1,913
  • 13
  • 14
0

In find_item you are setting @post, not @item, which makes it nil on the view.

Leonel Galán
  • 6,993
  • 2
  • 41
  • 60
0

ActiveRecord automatically gives you getter and setter methods for the instance attributes. @item.title calls title method on the @item object. If the method is not defined on the object on which it is being called then NoMethodError exception is raised.

The error that you see when you access show is because @item instance variable is not initialized in the controller and thus not available in the view file show.html.erb, i.e. it is nil by default and Rails is complaining that there is no method title on the nil object(as nil object doesnt have that method, @item or @post might have it depending on whether the respective table has that column)

Alok Swain
  • 6,409
  • 5
  • 36
  • 57