Daniel Hill
Daniel Hill

Reputation: 1

Using the imdb gem to show and its poster function in an erb file with sinatra and ruby

I am trying to access posters(from imdb gem) in a Ruby server using sinatra and then display them in my view (erb file). It show an error(undefined method for poster) but shows no error if I apply the code with .movies as below. Below is the calling of imdb gem and my code from the erb. Hope someone can help me as I am new to using gems. Thanks.

# This is the file from my server.rb file in sinatra 
# The :search_term takes an input from a HTML form.
post "/calculate" do
  movie = params[:search_term]
  search1 = Imdb::Search.new(movie)
  @output = search1 
  @output.movies
  redirect "/movie_result"
end

#erb file content
'<%= @output %>'

Upvotes: 0

Views: 92

Answers (1)

user6183958
user6183958

Reputation:

It is not about gems. It's about request, response cycle. Let me show you your mistake.

When client sends some params to you with post method, your code makes a processing and then responses with redirect. Not with any local parameters to manipulate and show inside a view file.

Rendering a view file with local params is different from redirecting an action to a new route.

consider example.

routes.rb

get '/mocko' do
  @x = "Mocko"
  redirect '/locko'
end

get '/locko' do
  erb :locko, :layout => false
end

locko.erb

Is there x?<strong><%= @x.nil? ? "No" : "Yes" %></strong>

Output (When I request for mocko it redirects me locko immediately)

enter image description here

P.S. Let me know if you'll able to solve from there on.

Upvotes: 2

Related Questions