Reputation: 231
I have a rails movie app and the movie info that will be featured on the site will be from TMDB.
Using the TMDB-Ruby gem, i can already produce results (info) from a movie, but now i need to know how to extract that returned info and save it to my database.
So if i run
TmdbMovie.find(:title => "fight club", :limit => 10, :expand_results => true, :language => "en")
in the rails console, it will show me info about that movie.
So How can I, from that returned info, create a new movie and save say the :title
and the :description
Upvotes: 1
Views: 764
Reputation: 1511
Looking at the documentation you can do it like this assuming you have a Movie class with the appropriate migrations for title and description.
movie = TmdbMovie.find(:title => "Iron Man", :limit => 1)
@movie.title = movie.title
@movie.description = movie.description # Not sure if the returned data contains a description
@movie.save
EDIT~ In update to below comment.
Let's say you have your MovieController and a user is a searching for the movie through a search field which would be in params[:search] and the movie returned would be stored in the database. If this is being done in the index action it would look like below.
def index
movie = TmdbMovie.find(:title => params[:search], :limit => 1)
@movie = Movie.new
@movie.title = movie.title
@movie.description - movie.description
@movie.save
end
Upvotes: 3