Skip to content

Instantly share code, notes, and snippets.

@andersosthus
Created February 15, 2011 20:39
Show Gist options
  • Save andersosthus/828198 to your computer and use it in GitHub Desktop.
Save andersosthus/828198 to your computer and use it in GitHub Desktop.
ActionView::Template::Error (undefined method `model_name' for PatchedOpenStruct:Class): 1: $("#searchresults").html("<%= escape_javascript(render(@searchresults)) %>");
<% @searchresults.each do |movie| %>
Found: <%= movie.name %> | <%= movie.id %><br />
<% end %>
<center><h1>My movies</h1></center>
<%= form_tag movies_path, :method => :get, :remote => true do %>
<p>
<%= search_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
<div id="searchresults">
<% if not @searchresults.nil? %>
<%= render @searchresults %>
<% end %>
</div>
<hr>
<%= render 'layouts/movies' %>
$("#searchresults").html("<%= escape_javascript(render(@searchresults)) %>");
class MoviesController < ApplicationController
def index
@title = "My movies"
@movies = Movie.all
if params[:search]
Tmdb.api_key = "XXX"
@searchresults = TmdbMovie.find(:title => params[:search], :expand_results => false)
end
end
end
@aarongough
Copy link

Hey Anders!
Just having a look over this code now... It doesn't look like this is an issue with ruby-tmdb, instead it is a small typo in your rails code.

In index.html.erb

 render @searchresults

Should be:

render :partial => "searchresults"

I would also recommend moving the Tmdb.api_key call into an initializer rather than calling it in your controller.

Hopefully this fixes the problem for you!
Regards,
Aaron

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment