Action for a borrow button on the Rails

Asked

Viewed 150 times

0

I’m just starting out on ruby on Rails and I’m having a question I need to make a library, I created and I am listing the books, I created a borrow button in each book unit and then this my problem I want to make this button to be clicked already take to the loan page the book ID, I even managed to do that but when I’m going to save the loan he makes a mistake.

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 so:

Lend button on 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 so:

<%= 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 line 4 error:

3 <div class="form-group">

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

5 </div>
  • In the mistake you put here, can you get the line number and also put it here for us? Seeing exactly the line from where this error occurs will be much easier to help you

1 answer

0

Class name should always come with uppercase letter, example: Livro.find, therefore the mistake 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
  • True dear, but in my project this in capital yes e pq copied this excerpt of code here in hand msm and ended up missing. I will even edit now.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.