0

I've a problem with rails 4. I used this code with Rails 3. Now, i'm using the same with Rails 4 in another application and i got the message "wrong number of arguments (4 for 5) on the first line.

   <%= form_for :customer,
    :url => Braintree::TransparentRedirect.url,
    :params => @result && @result.params[:customer],
    :builder => ApplicationHelper::BraintreeFormBuilder,
    :errors => @result && @result.errors.for(:customer) do |f| %>
    <%= field_set_tag "Customer" do %>
    <dl>
        <dt><%= f.label :first_name, 'First Name' %></dt>
        <dd><%= f.text_field :first_name %></dd>
        <dt><%= f.label :last_name, 'Last Name' %></dt>
        <dd><%= f.text_field :last_name %></dd>
        <dt><%= f.label :phone, 'Phone' %></dt>
        <dd><%= f.text_field :phone %></dd>
    </dl>
    <% end %>
    <%= field_set_tag "Credit Card" do %>
    <% f.fields_for :credit_card do |cc| %>
    <dl>
        <dt><%= cc.label :number, 'Number' %></dt>
        <dd><%= cc.text_field :number %></dd>
        <dt><%= cc.label :expiration_date, 'Exipration Date (MM/YY)' %></dt>
        <dd><%= cc.text_field :expiration_date %></dd>
        <dt><%= cc.label :cvv, 'CVV' %></dt>
        <dd><%= cc.text_field :cvv %></dd>
    </dl>
    <% end %>
    <% end %>
    <%= hidden_field_tag :tr_data, @tr_data %>
    <%= f.submit 'Save Payment Info' %>
    <% end %>

EDIT : It seems the problem comes from "builder: ApplicationHelper::BraintreeFormBuilder,"

guilb
  • 119
  • 1
  • 2
  • 11

2 Answers2

4

Just providing some additional information to corroborate the answer from @cschroed...

If you're like me, you've likely copied some example Braintree code into your app from here.

Rails 4 changed the call to the builder interface as @cschroed mentioned. All you need to do is update your local copy of the example code to match the new interface. For me this was as simple as changing

class BraintreeFormBuilder < ActionView::Helpers::FormBuilder
   ...
   def initialize(object_name, object, template, options, proc)

to

class BraintreeFormBuilder < ActionView::Helpers::FormBuilder
   ...
   def initialize(object_name, object, template, options)
Joseph Siefers
  • 1,282
  • 1
  • 12
  • 23
2

I don't know anything about the BraintreeFormBuilder but I would check to see if ApplicationHelper::BraintreeFormBuilder is Rails 4 compatible and if you have installed the correct version. You are passing that as a :builder into form_for, but the way the builder is called from \action_view\helpers\form_helper.rb changed from Rails 3 to Rails 4. In Rails 3 it is:

builder.new(object_name, object, self, options, block)

In Rails 4 it is:

builder.new(object_name, object, self, options)

So if your version of ApplicationHelper::BraintreeFormBuilder is still expecting 5 arguments, but Rails 4 is now passing 4, you'd see an error like the one you have.

To narrow in on where an error like this is really occurring, you may have to view the Framework Trace rather than the Application Trace. If you are using a gem like better_errors this means clicking the "All Frames" option rather than just viewing the "Application Frames" when the error occurs.

cschroed
  • 6,304
  • 6
  • 42
  • 56