1

I have a form that allows users to manually input movies to review. Additionally, I am pulling movies from an external API (TMDB). When the user searches, it shows all results from the database as well as another area where data is pulled from the API. I want them to be able to click on a thumbnail from the external API and pre-populate my "new" form with that data. This code currently goes to the "new" form, but the title and description are not populated like I want them to be (a blank new form is rendered).

<% if @movies_api %>
<div class="row">
  <% @movies_api.each do |movie| %>
    <% if movie.poster_path %>
    <div class="col-sm-6 col-md-3">
      <div class="thumbnail">
        <%= link_to(image_tag('https://image.tmdb.org/t/p/w396' + movie.poster_path, class: 'image', size:"400x600"), {:action => 'new', :controller => 'movies'}, :title => movie.title, :description => movie.overview ) if movie.poster_path %>
      </div>
    </div>
    <% end %>
  <% end %>
<% end %>

How do I accomplish pre-populating the new form with data I gather from the API?

1 Answer 1

1

I figured out a way to do this. In my form, I can do:

  <div class="field">
    <%= f.label :title %><br>
    <%= f.text_field :title, :value => params[:title] %>
  </div>

Not sure if there is a better way, but this works :-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.