mardi 17 janvier 2017

NameError in CoursesController#index

I was taking the course on ruby on rails from courser and i encountered this error which was not even mentioned on FAQs page. I am posting model files, view files and controller files. Please provide me a solution to it.The error i got when i typed www.localhost:3000/courses/index is given in this screenshot. Click here

            courses_controller.rb
class CoursesController < ApplicationController
   def index
        @search_term = params[:looking_for] || 'jhu'
        @courses = Coursera.for(@search_term)
   end
end


                 coursera.rb

class Coursera
   include HTTParty
   default_options.update(verify: false) # Turn off SSL verification
   base_uri 'http://ift.tt/1OxnZ5U'
   default_params fields: "smallIcon,shortDescription", q: "search"
   format :json

   def self.for term
      get("", query: { query: term})["elements"]
   end
end

              index.html.erb
<h1>Searching for - <%= @search_term %></h1>
<table border="1">
   <tr>
       <th>Image</th>
       <th>Name</th>
       <th>Description</th>
   </tr>
   <% @courses.each do |course| %>
      <tr class=<%= cycle('even', 'odd') %>>
          <td><%= image_tag(course["smallIcon"])%></td>
          <td><%= course["name"] %></td>
          <td><%= course["shortDescription"] %></td>
      </tr>
   <% end %>
</table>

Aucun commentaire:

Enregistrer un commentaire