Search code examples
ruby-on-railsrubyruby-on-rails-3flickr

Rails - undefined method `delete' for nil:NilClass


I'm getting the undefined method error when trying to run a search on Flickr using the Flickraw gem.

I'm quite new to Rails and have tried a few different methods but can't seem to get it to work.

Here is my application.html.erb,

<html>
<head>
 <title>Workspace</title>
 <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
 <%= javascript_include_tag 'application', 'data-turbolinks-track' => true%>
 <%= csrf_meta_tags %>
</head>
<body>
 <%= form_tag controller: "photos", action: "search", class: "navbar-form navbar-left", method: "get" do %>
 <div class="form-group">
   <%=text_field_tag :search, params[:text]%>
 </div>
 <%= submit_tag "Search", class: "btn btn-default" %>
 <% end %>

<%= yield %>
</body>
</html>

Here is my PhotosController,

class PhotosController < ApplicationController

require "flickraw"

def index
    @list = flickr.photos.getRecent
end

def search
    @results = flickr.photos.search(params[:text => "text"])
end
end

I thought that by passing the text parameter it would return with a list of public photos related to the text input.

Any help is appreciated.


Solution

  • params[:text => "text"] this is looking in the params hash for an entry with the key :text => text. It's extremely unlikely that this is actually what you wanted to do.

    What you probably want is this:

    @results = flickr.photos.search(params[:text] => "text")
    

    (or something else like it... which matches how the search method works... which I don't know I'm just guessing)

    Possibly more like just this:

    @results = flickr.photos.search(params[:text])