Larry Qu

Joined

2,650 Experience
23 Lessons Completed
0 Questions Solved

Activity

Posted in rails testing always raise the same error

No matter which test file does I run, it always raise this error.
I don't konw how to fix this, thanks!


$rails test test/integration/about_test.rb
Running via Spring preloader in process 5244
Run options: --seed 35591

# Running:

E

Error:
AboutTest#test_can_see_the_about_page:
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_admin_users_on_email"
DETAIL:  Key (email)=() already exists.
: INSERT INTO "admin_users" ("created_at", "updated_at", "id") VALUES ('2017-03-10 07:58:35.156623', '2017-03-10 07:58:35.156623', 298486374)



bin/rails test test/integration/about_test.rb:8



Finished in 0.298578s, 3.3492 runs/s, 0.0000 assertions/s.

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

I want to add or upload multiple images in one product, but after I implement this , the active_admin edit product page error.

in products_controller.rb, permit the images , which type is json {images: []}.

    def product_params
      params.require(:product).permit(:name, :description, :price, :main_image, `{images: []}`)
    end

in products/_form.html.erb, I add multiple image upload tag <%= f.file_field :images, multiple: true, class: "form-control" %>

<%= form_for(product) do |f| %>
  <% if product.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(product.errors.count, "error") %> prohibited this product from being saved:</h2>

      <ul>
      <% product.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field form-group">
    <%= f.label :name %>
    <%= f.text_field :name, class: "form-control" %>
  </div>

  <div class="field form-group">
    <%= f.label :description %>
    <%= f.text_area :description, class: "form-control" %>
  </div>

  <div class="field form-group">
    <%= f.label :price %>
    <%= f.text_field :price, class: "form-control" %>
  </div>

  <div class="field form-group">
    <%= f.label :main_image %>
    <%= f.file_field :main_image, class: "form-control" %>
  </div>

  <div class="field form-group">
    <%= f.label :images %>
    <%= f.file_field :images, multiple: true, class: "form-control" %>
  </div>

  <div class="actions">
    <%= f.submit "update", class: "btn btn-primary" %>
  </div>
<% end %>

when use active_admin to edit one product, error occured
http://localhost:3011/admin/products/4/edit

 Showing /Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/app/views/active_admin/resource/edit.html.arb where line #2 raised:

Unable to find input class JsonInput

Extracted source (around line #336):

        @input_class_finder.find(as)
      rescue Formtastic::InputClassFinder::NotFoundError
        raise Formtastic::UnknownInputError, "Unable to find input #{$!.message}"
      end

      # @api private

Rails.root: /data/ruby-apps/siziwang_travel
Application Trace | Framework Trace | Full Trace

formtastic (3.1.5) lib/formtastic/helpers/input_helper.rb:336:in `rescue in namespaced_input_class'
formtastic (3.1.5) lib/formtastic/helpers/input_helper.rb:333:in `namespaced_input_class'
formtastic (3.1.5) lib/formtastic/helpers/input_helper.rb:342:in `input_class'
formtastic (3.1.5) lib/formtastic/helpers/input_helper.rb:240:in `input'
formtastic (3.1.5) lib/formtastic/helpers/inputs_helper.rb:330:in `block in fieldset_contents_from_column_list'
formtastic (3.1.5) lib/formtastic/helpers/inputs_helper.rb:318:in `collect'
formtastic (3.1.5) lib/formtastic/helpers/inputs_helper.rb:318:in `fieldset_contents_from_column_list'
formtastic (3.1.5) lib/formtastic/helpers/inputs_helper.rb:297:in `inputs'
arbre (1.1.1) lib/arbre/rails/forms.rb:30:in `proxy_call_to_form'
/Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/lib/active_admin/views/components/active_admin_form.rb:60:in `inputs'
/Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/lib/active_admin/views/pages/form.rb:45:in `block in default_form_config'
/Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/lib/active_admin/views/components/active_admin_form.rb:35:in `instance_eval'
/Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/lib/active_admin/views/components/active_admin_form.rb:35:in `build'

after delete this: data-disable-with="Add to Cart", still not work.

Thank you Chris!
I wish a complete video about how to Integrate simplemde and rails。

The purpose is add product to cart, target is blank.

After I submit(click) the form(submit input tag), the submit tag become disabled, how can I avoid this?
I need it is always enabled for click.

part of products#index html

<div class="product">
            <div class="product-info product-name">土豆</div>
            <div class="product-info product-description">个大,均匀,甘甜。</div>
            <div class="product-info product-price">¥2.5/ 斤</div>
            <div class="product-info">
    <%= form_for(@cart, namespace: @product.id, target: "_blank") do |f| %>
        <%= f.hidden_field :product_id, value: @product.id, namespace: @product.id %>
        <% if current_user %>
        <%= f.hidden_field :user_id, value: current_user.id, namespace: @product.id %>
        <% end %>

        <div><%= f.number_field :amount, min: 1, max: 100, value: 1, required: true,  namespace: @product.id %> 斤</div>
        <div><%= f.submit "加入购物车", class: 'btn btn-primary' %></div>
    <% end %>
            </div>
</div>

application.js

$(document).on('turbolinks:load', function() {
    $('input[type=submit]', this).attr('disabled', false)
    $(".new_cart").attr({
        target: '_blank'
    });

});

This video show the problem

yes, solved! Thank you !
After I manually require scss files, no longer use require_tree it works fine.

 *= require_self
 * require_tree . // not used
 *
 *= require addresses.scss
 *= require carts.scss
 *= require checkout.scss
 *= require full-width-pics.scss
 *= require order_items.scss
 *= require orders.scss
 *= require products.scss
 *= require scaffolds.scss
 *= require services.scss
 *= require startup.scss
 */

After adding the activeadmin gem, my previous style changed , How can avoid this?

Previous style is :

After adding the activeadmin gem, the style become this:

but if I comment the active_admin scss out, the admin page will have no style.
active_admin.scss

@import "active_admin/mixins";
@import "active_admin/base";

Yes! Thank you very much!

I am very confused that checkout button also can not submit, until after refresh.

see video

Thank you for help me refactor the code.
I replace table with div , div and form works well together.

About form and table, if use form in table , must include it completely in td tag.

form in td completely, validate pass.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table>
    <tr>
        <td>
            <form action="http://www.baidu.com">
                <input type="text" name="w" value="a">
                <input type="submit">
            </form>
        </td>
    </tr>
</table>
</body>
</html>

form in tr , out of td, validate error.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table>
    <tr>
      <form action="http://www.baidu.com">
        <td>
                <input type="text" name="w" value="a">
                <input type="submit">
        </td>
      </form>
    </tr>
</table>
</body>
</html>

Resources
validate
netsting form and table

I remove it, restart the server, but still not work.

I'am not disable turbolinks manually, it's default from rails 5.0.1.
How to make sure it works ?

Gemfile

gem 'turbolinks', '~> 5'

application.js

//= require turbolinks

submit just use form, not use js.
products.html

<table class="table table-striped">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
      <th>Price</th>
      <th>Show</th>
      <th>Edit</th>
      <th>Destroy</th>
      <th>Amount</th>
      <th>购买</th>
      <th colspan="5"></th>
    </tr>
  </thead>

  <tbody>
      <tr>
        <form action="/carts" method="post" target="_blank">
          <td>羊肉</td>
          <td>纯天然羊肉,秋冬滋补佳品。</td>
          <td>30.0</td>
          <td><a href="/products/1">Show</a></td>
          <td><a href="/products/1/edit">Edit</a></td>
          <td><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/products/1">Destroy</a></td>

          <input name="cart[product_id]" value=1 type="hidden" />
          <input name="cart[user_id]" value=2 type="hidden" />

          <td><input type="number" name="cart[amount]" required="true" min="1" max="100" value="1" autofocus="true"> 公斤</td>
          <td><button type="submit" class="btn btn-primary">Add to Cart</button></td>


      </tr>
      <tr>
        <form action="/carts" method="post" target="_blank">
          <td>牛肉</td>
          <td>纯天然牛肉</td>
          <td>30.0</td>
          <td><a href="/products/2">Show</a></td>
          <td><a href="/products/2/edit">Edit</a></td>
          <td><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/products/2">Destroy</a></td>

          <input name="cart[product_id]" value=2 type="hidden" />
          <input name="cart[user_id]" value=2 type="hidden" />

          <td><input type="number" name="cart[amount]" required="true" min="1" max="100" value="1" autofocus="true"> 公斤</td>
          <td><button type="submit" class="btn btn-primary">Add to Cart</button></td>


      </tr>
  </tbody>
</table>

I have recored a video to show the problem, please see the video . Thank you very much!

See Video

after I switch the controller, and switch back, the form submit button Failure, if I refresh the page , it can works again.
the console and network no error log.