I’m looking to take an example of a model (in this case, Book), and render a specific instance of that model by ID.
The model is just a basic scaffold generated model – usual show method;
def show
@book = Book.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @book }
end
end
I’m looking to embed an instance of this inside of the view:
<div class="tab-pane active" id="tab1">
<%= render :template "books/show", :book => 1 %>
</div>
There’s something I’m doing wrong here, I can tell. But I don’t know where to proceed from here! Any help is really appreciated. I know I need to somehow pass the book ID, but I can’t figure out how to do that. Thanks!
<%= render :template "books/show", :book => 1 %>only renders the partial, it doesn’t load the page.What you need to do is call the route
"books/show/#{book_id}"from an iframe for example.