Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to input the model field as a string (undefined method `b' for :title:Symbol)

Im using the IMDB gem. To do a search with it, you need

movie_list = Imdb::Search.new("title as a string")

In my application, I use a form to take in a movie title and save it as a field in the model table. I want to use the value :title for the search.

When I do

movie_list = Imdb::Search.new(:title)

I get the error, "undefined method `b' for :title:Symbol"

Is this correct?

movie_list = Imdb::Search.new("{#{:title})

Here is how I use the code:

class Movie < ActiveRecord::Base
    has_many :actors, dependent: :destroy
    after_create :fill_actors_table
    validates_presence_of :title

    def fill_actors_table
       # can't figure out how to insert string. :title
       # "Lion King works"  
       movie_list = Imdb::Search.new("Finding Nemo")
       new_movie = movie_list.movies.first
      id = new_movie.id

      i = Imdb::Movie.new("#{id}")
      i.cast_members.each do |actor_name|
        actor_image = Google::Search::Image.new(:query => actor_name).first
        actor_image_url = actor_image.uri
        Actor.create(:name => actor_name, :file => actor_image_url)
      end
    end
like image 269
chiefkikio Avatar asked Nov 19 '25 07:11

chiefkikio


1 Answers

:title is a symbol. It has no other meaning except being a symbol with value :title. The initializer expect you to pass a string.

Assuming you are fetching the parameter from a request, you probably want to use params[:title].

movie_list = Imdb::Search.new(params[:title])

As a side note, you may also want to have a look at some basic Ruby documentation and books before proceeding. It looks like you're very new to it.

like image 80
Simone Carletti Avatar answered Nov 20 '25 19:11

Simone Carletti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!