Action for a lend button in rails

0

I'm starting right now in ruby on rails and I'm having a question I need to make a library, I created and I am listing the books, I also created a button to borrow in each book unit and there it is my problem I want to make this button to be clicked already take to the page of loan the ID of the book, this I even managed to do it, but when I save the loan, it is an error.

I created this method:

def load_livro
      if params[:livro_id]
        @livro = livro.find(params[:livro_id])
      else
        @livro = livro.new
      end
 end

And I called him like this:

lend button in app / views / books / index.html.erb:

<td class="col-xs-1"><%= link_to 'Emprestar', "/emprestimo/new/#{emprestimo.id}" %></td>

And on the loan page I used it like this:

<%= f.hidden_field :livro_id, :value => @livro.id %>

In this last line of code the following error occurred:

Undefined local variable or method 'livro'  did  you mean? livro_url

Code snippet with error line 4:

3 <div class="form-group">

4   <%= f.hidden_field :livro_id, :value => @livro.id %>

5 </div>
    
asked by anonymous 26.04.2018 / 14:53

1 answer

0

The name of the class should always be in uppercase, for example: Livro.find , so the error Undefined local variable or method 'livro'

def load_livro
      if params[:livro_id]
        @livro = Livro.find(params[:livro_id])
      else
        @livro = Livro.new
      end
 end
    
26.04.2018 / 16:46