Giter Club home page Giter Club logo

dry_crud's People

Contributors

amaierhofer avatar codez avatar cschweingruber avatar daniel-illi avatar duritong avatar kronn avatar mberlanda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dry_crud's Issues

[PG::UndefinedFunction: ERROR] Search raising errors with date and numeric columns

Hi,

I am facing the following error for the controllers where I have in my search columns some date or numeric fields (such as related models):

PG::UndefinedFunction: ERROR:  operator does not exist: date ~~* unknown
LINE 1: ...ents".* FROM "events" WHERE (((((("events"."date" ILIKE '%ap...

The error is pretty clear and it's due to the implementation of the search method.

Feature suggested : Add Datatables for index

I am wondering if you would interested to provide the integration with some table plug-in for jQuery such as Datatables.

The implementation sounds quite workable to me:

The Table Builder should:

  • create only the headers of the table
  • assign to the table a unique id
  • eventually create a div with unique id for table buttons

An haml representation of the output could be:

.container
  .crud-index-buttons
  %table.table.table-striped.table-bordered#crud-table
    %thead
      - Controller.search_columns.each do |col|
        %tr= I18n.t("something.#{col}", default: col)

May I ask you some help to accomplish this first step?

The assets should include jquery.js, datatables.css, datatables.min.js.

The routes should include by default for every controller something like:

resources :model do
  collection do
    get :datatable_index
  end
end

It would be needed a decorator or an helper to transform the ActiveRecord::Collection to an array of array of values: e.g. an implementation I did on a previous project using concerns:

def model_datatable_index(model)
  @response = model.send(:all)
  @data = @response.map { |r| decorator_name.send(:new, r).send(:index) }
  render_datatable_response
end

private

def render_datatable_response
  respond_to do |format|
    format.json { render 'shared/search' }
  end
end

Where shared/search is a jbuilder json:

# app/views/shared/search.json.jbuilder
json.draw params['draw'].to_i
json.recordsTotal @data.count
json.recordsFiltered @data.count
json.data @data

Finally the view should initialize DataTable on document ready.:

$(
  function() {
    initializeCrudTable(url,tableId, buttonsIdOrClass);
  }
)

function initializeCrudTable(url,tableId, buttonsIdOrClass){
  var crudTable = $(tableId).DataTable({
    'buttons': ['copy', 'excel', 'pdf'],
    'processing': true,
    'scrollX': true,
    'pageLength': 50,
    'order': [[1, 'asc']],
    'ordering': true,
    'dom': 'fl<"table-scrollable"t>irp',
    'columnDefs': [
      {
        targets: [],
        orderable: true
      }
    ],
    'ajax': {
      'url': url,
      'method': 'GET'
    }
  });
  new $.fn.dataTable.Buttons( crudTable, {
    buttons: [
      'copy', 'excel', 'pdf'
    ]
  });
  crudTable.buttons().container().appendTo( $(buttonsIdOrClass) );
}

I would be glad to create a pull request adding this feature, but I would need some help to complete the first step.

Thank you very much!

Mauro

admin /namespace support?

I am trying to use dry_crud with a model called Category under a namescope of admin.

Does dry_crud support this feature or do I need to modify all the views myself for this?
the views are all trying to use new_category_path instead of new_admin_category_path

Spec don't run with error: superclass mismatch for class Col (TypeError)

I am run
rails generate dry_crud --templates haml --tests rspec
then run generated specs and get error:

/home/charger/projects/myproject/app/helpers/standard_table_builder.rb:103:in `<class:StandardTableBuilder>': superclass mismatch for class Col (TypeError)
    from /home/charger/projects/myproject/app/helpers/standard_table_builder.rb:8:in `<top (required)>'
    from /home/charger/.rvm/gems/ruby-1.9.3-p374@global/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
    from /home/charger/.rvm/gems/ruby-1.9.3-p374@global/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
    from /home/charger/.rvm/gems/ruby-1.9.3-p374@global/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /home/charger/.rvm/gems/ruby-1.9.3-p374@global/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
    from /home/charger/projects/myproject/spec/spec_helper.rb:34:in `block (2 levels) in <top (required)>'
    from /home/charger/projects/myproject/spec/spec_helper.rb:34:in `each'
    from /home/charger/projects/myproject/spec/spec_helper.rb:34:in `block in <top (required)>'
    from /home/charger/.rvm/gems/ruby-1.9.3-p374@global/gems/spork-0.9.2/lib/spork.rb:37:in `each_run'
    from /home/charger/projects/myproject/spec/spec_helper.rb:26:in `<top (required)>'
    from /home/charger/projects/myproject/spec/controllers/crud_test_models_controller_spec.rb:1:in `require'

standard_table_builder.rb:103:

class Col < Struct.new(:header, :html_options, :template, :block) #:nodoc:

    delegate :content_tag, :to => :template

    def content(entry)
      entry.nil? ? '' : template.capture(entry, &block)
    end

    def html_header
      content_tag :th, header
    end

    def html_cell(entry)
      content_tag :td, content(entry), html_options
    end

  end

Any specs don't run. How solve this problem?

Unable to sign_in in CrudTestModelsController specs

I would like firsty to congratulate for the great job.

I am having some hard time to get the default tests to pass.

In my Gemfile I have:

gem 'rails', '~> 5.0.2'
gem 'devise', '~> 4.3'
gem 'rspec-rails', '~> 3.6.0'

ruby '2.4.0'

Requiring Support Files

The first issue I faced to pass the gem auto-generated test was to require automatically all files in support folder by adding to spec/rails_helper.rb

Dir[File.expand_path('../support/*.rb', __FILE__)].each {|file| require file }

Authenticate in Controllers specs

Since I am using Devise gem for authentication, the most of controller's specs fail due to authentication issues. My initial setup was:

# spec/support/devise.rb
RSpec.configure do |config|
  config.include Devise::Test::ControllerHelpers, type: :controller
end

I firstly tried the usual behavior of Rspec and Devise:

# spec/controllers/crud_test_models_controller_spec.rb
describe CrudTestModelsController do
  before(:all) do
    reset_db
    setup_db
    create_test_data

    user = FactoryGirl.create(:user)
    sign_in user
  end

But it seems that crud_test_models_controller_spec.rb is acting like an integration test - such as Capybara tests - so I encountered the following issue:

   NoMethodError:
     undefined method `env' for nil:NilClass 

So I have added the @request.env as follows

# spec/controllers/crud_test_models_controller_spec.rb

  before(:all) do
    #...
    @request.env["devise.mapping"] = Devise.mappings[:user]
    @user = FactoryGirl.create(:user)
    sign_in @user
  end
       Failure/Error: @request.env["devise.mapping"] = Devise.mappings[:user]
       
       NoMethodError:
         undefined method `env' for nil:NilClass
       # ./spec/controllers/crud_test_models_controller_spec.rb:17:in `block (2 levels) in <top (required)>'

Based on this StackOverflow answer, I have changed my test as follows:

# spec/controllers/crud_test_models_controller_spec.rb
describe CrudTestModelsController, type: :controller do
  include CrudTestHelper
  include Devise::Test::IntegrationHelpers

  before(:all) do
    reset_db
    setup_db
    create_test_data

    @user = FactoryGirl.create(:user)
    sign_in @user
  end

From the test output I have attached, it seems that it is not logging in properly.
crud_test_models_controller_spec.pdf
I tried then to implement the login_as authentication using include Warden::Test::Helpers without different results.

I also tried to downgrade devise gem to 4.1 for a different testhelper suite, but still the same issue.

This is the repository where I am trying to integrate dry_crud: https://github.com/mberlanda/cheidelacoriera

Do you have any idea of I could I make it work properly?

Thanks

search bar doesn't show up in view

im on rails 5.0.6 and ruby 2.4.3
I added a categories controller:

class CategoriesController < CrudController
self.search_columns = [:name, :description]
end

I can do everything with the controller, but a search bar never appears. there is no error, what can I do?

btw, love the project,been writing my own for years, but I'll use this going forward.

uninitialized constant DryCrud::Responder

class CrudController < ListController

self.responder = DryCrud::Responder
..............
.............
end

"self.responder = DryCrud::Responder"
This line is generating uninitialized constant DryCrud::Responder error. I am using dry crud in rails engine in my application.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.