Undefined Method in HTTParty class
-
22-07-2021 - |
Вопрос
I'm somewhat new to rails and every time I think I'm getting it I hit a wall.
I'm using HTTParty
and this API. I am just trying to get a response to show up in my index view to get the lowest level of the api working.
It worked for me in the console but not when I tested it in the API. I'm getting an
undefined method `picture' for Snapshots:Class
error for my index view.
Here is the HTTParty class
class Snapshots
include HTTParty
def initialize
@sitename = "google.com"
end
def picture
response = HTTParty.get("http://api.snapito.com/web/516e011353b62078731712566b01e143f56adf0b/full/diditmatter.herokuapp.com/lists")
if respone.success?
response
end
end
end
Here is my lists controller
def index
@it_works = Snapshots.picture
respond_with(@lists = List.all)
end
And here is list view
<%= @it_works %>
<h1 class="page-header">Projects at a glance</h1>
<div class="span12 offset2">
<% @lists.each do |list| %>
<div class="well row span4">
<div class="span3">
</div>
<div class="span4">
What do I seem to be overlooking here?
EDIT
@Benjamin fix worked, but I've come across a problem I'm not sure is related to rails. I'm not sure is I should open another question. But since the context is here and I'm not really even sure how to search this, I have to follow up here.
That instance variable is returning the attached screen shot. Is this related to how I'm calling it from the API I linked to in the first paragraph?
I've never seen this so not to sure where to look or how to approach.
Решение
You are treating the picture
method as a class method. Change it to this: @it_works = Snapshots.new.picture