2

I am new to ruby on rails and am composing a library for books. Most of it is working except for moving a scanned in isbn from a text field on a page to another text field.

<%= form_for @book, :html => { :class => 'form-horizontal' } do |f| %>
  <div class="control-group">
    <%= f.label :isbn, :class => 'control-label' %>
    <div class="controls">
      <%= f.text_field :isbn, :class => 'text_field' %>
      <%= link_to t('.new_autofill', :default => t("helpers.links.Auto Fill")),
            autofill_books_path( :isbnvalue => :isbn ),
            :class => 'btn btn-primary' %>
    </div>
  </div>
  <div class="control-group">

The code above takes the value isbn and passes it into the controller that sets up the page autofill. I need the isbn text_field value, not its label value which is what I think I am obtaining. How do i grab this value? Thank you for any help.

1 Answer 1

1

You can use Javascript to do that as outlined in this SO post.

If you want to do it with rails, you can create a new action in the book controller and link to it in the form instead of autofill_books_path, for instance get_isbn:

def get_isbn
  @isbn = params[:book][:isbn]

  redirect_to autofill_books_path(isbnvalue: @isbn)
end

Of course you should include validation to check if the isbn provided is correct.

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.