Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4 support #1443

Closed
ai opened this issue Dec 18, 2012 · 43 comments
Closed

Rails 4 support #1443

ai opened this issue Dec 18, 2012 · 43 comments

Comments

@ai
Copy link
Contributor

ai commented Dec 18, 2012

Ruby on Rails 4 is now beta and will be released very soon.

It will be nice, if RailsAdmin will support Rails 4.

Now RailsAdmin is locked on rails ~> 3.1. Is it code dependency, which need real strong refactoring?

@gunn
Copy link
Collaborator

gunn commented Dec 18, 2012

Yeah it needs real work, more than just bumping that number up. Want to have a crack at it in new branch?

@ai
Copy link
Contributor Author

ai commented Dec 18, 2012

Maybe you already have a list of problems?

@gunn
Copy link
Collaborator

gunn commented Dec 18, 2012

I just tried updating the Gemfile and there were enough problems that it didn't look trivial.
If you get started, I'll try to help out, else I'll probably have a go sometime later.

Strong parameters is the first problem.

@ai
Copy link
Contributor Author

ai commented Dec 18, 2012

I create really painful hacks, but RailsAdmin work with (and only with) my project :).

I can create real fixes only later. But today I can write problem places, that I found.

@ai
Copy link
Contributor Author

ai commented Dec 18, 2012

My problems with Rails 4:

  1. lib/rails_admin/config.rb:206: Rails now doesn’t have Rails::Application::Railties.engines.
  2. All assets path goes with engine base URL (like admin/assets/rails_admin.js).
  3. lib/rails_admin/config/model.rb:59: need abstract_model.model.model_name.to_s.demodulize.underscore.
  4. Attributes access in lib/rails_admin/adapters/active_record/abstract_object.rb:19 and lib/rails_admin/config/fields/base.rb:218.

@gunn
Copy link
Collaborator

gunn commented Dec 18, 2012

Do you mean you have rails_admin working with your rails 4 project?
Your hacks might be useful to see. Post what you have anyway.

If I have time I might make a start tomorrow

@ai
Copy link
Contributor Author

ai commented Dec 18, 2012

Yeap, rails4 branch run with Rails 4 project, can create/edit and delete records. I don’t run the tests and hacks are really rude and immoral :).

@gunn
Copy link
Collaborator

gunn commented Dec 18, 2012

Cool, that's a good start

@pboling
Copy link

pboling commented Jan 6, 2013

@ai & @gunn there is a pull request to rails to fix the asset path problem.

@gbmoretti
Copy link

Anyone have news about the Rails 4 support?

@PikachuEXE
Copy link
Contributor

@gbmoretti Maybe wait until beta2 or rc1 is out...

@gbmoretti
Copy link

I'm trying that, and as well as @ai I have an application running with Rails 4 and rails_admin but tests don't pass.
Almost all errors concerning to the rails internal gems...
Maybe it's better wait for a stable version, indeed.

@davebrace
Copy link

Any chance we could start a Rails-4.0 branch to start work on migrating rails_admin to support Rails 4? I spent a few hours trying to update rails_admin to work against 4.0, but its still a work in progress. I would love to make it a communal effort.

@bbenezech
Copy link
Collaborator

I added a rails-4 branch, feel free to send PR ;)

@smidwap
Copy link
Contributor

smidwap commented Apr 18, 2013

Just fired up the rails-4 branch on my app. I'm getting the following exception when trying to create a new record (e.g. /admin/groups/new)

undefined method `active_authorizer' for #<Class:0x007fac92ad2af0>

Looking at the rails_admin code, it appears as though there is a dependency on rails 3 mass assignment security (i.e. attr_accessible). The issue is that active_authorizer (which is a mass assignment Rails method) no longer exist in rails 4. The method is used to not display an attribute's form field if the attr_accessible does not permit mass assignment of that attribute.

Would it be reasonable to remove this feature?

@smidwap
Copy link
Contributor

smidwap commented Apr 18, 2013

Actually, the feature doesn't need to be removed entirely. Just the only way to make an attribute read_only would be via rails_admin config. See https://github.com/sferik/rails_admin/blob/rails-4/lib/rails_admin/config/fields/base.rb#L217

@mshibuya
Copy link
Member

While working on Mongoid Rails4 support, I've come up with a question:
May I cut off a support for Rails3(ActiveModel::MassAssignmentSecurity) style protection, or should try to support both of Rails4(ActiveModel::ForbiddenAttributesProtection) and Rails3 style protections?

Keeping backward compatibility is always good thing, but it might introduce some complexity to the logics.
How do you guys think of this?

@smidwap
Copy link
Contributor

smidwap commented Apr 28, 2013

Can't be sure, but I doubt mass assignment will be popular amongst Rails 4 developers. It's not a Rails default, and there's a suitable (arguably much better) replacement.

What relies on mass assignment beyond disabling form inputs for fields that can't be mass assigned?

@bbenezech
Copy link
Collaborator

It was a way to allow for column configuration through the mass assignement role.

We should ditch it and replace it with custom cancan verbs.

@jipiboily
Copy link

Adding my 2 cents here, for what's it worth ;)

I think you should go with Strong Parameter. Rails 3.2 apps can just add strong_parameter gem AFAIK and it would work out of the box.

@PikachuEXE
Copy link
Contributor

I am using strong_parameters already (Rails 3.2)
Hope other gems like devise would support it officially soon

@jipiboily
Copy link

@PikachuEXE you can monkey patch devise for now if you want: http://stackoverflow.com/questions/15520151/rails-4-authentication/15627422#15627422.

@PikachuEXE
Copy link
Contributor

@jipiboily I am using custom controllers anyway
So I just need to override resource_params

@fellz
Copy link

fellz commented Jun 5, 2013

Still no Rails 4 support when do you plan to add it ?

@mshibuya
Copy link
Member

mshibuya commented Jun 5, 2013

RailsAdmin 'rails-4' branch works nicely with Rails 4.0.0.rc1 now.
All specs pass both for AR and Mongoid.

@fellz
Copy link

fellz commented Jun 5, 2013

Didn't work with jquery-rails 3.0.0
Bundler could not find compatible versions for gem "jquery-rails":
In Gemfile:
rails_admin (>= 0) ruby depends on
jquery-rails (~> 2.1) ruby

jquery-rails (3.0.0)

Installed 2.3.0 version and then it works fine.

@mshibuya
Copy link
Member

mshibuya commented Jun 5, 2013

I've merged master into rails-4 branch.
'jquery-rails' version locking is fixed now(though travis is failing due to font-awesome issue, which I can't reproduce locally...).

@ai
Copy link
Contributor Author

ai commented Jun 5, 2013

With latest rails-4 patch catch File to import not found or unreadable: font-awesome. Fix it by extra gem 'font-awesome-sass-rails' in Gemfile.

@mshibuya
Copy link
Member

mshibuya commented Jun 5, 2013

Found the cause: seems to be sass-rails issue(ref. rails/sass-rails#139)
Locking sass-rails to github master by adding

gem 'sass-rails', github: 'rails/sass-rails'

to Gemfile worked.
Travis is passing again now :)

@swistaczek
Copy link

Problem with install rake task:

  rails g rails_admin:install
           -  Hello, RailsAdmin installer will help you set things up!
           -  I need to work with Devise, let's look at a few things first:
           -  Checking for a current installation of devise...
           -  Found it!
           -  Looks like you've already installed it, good!
           ?  Where do you want to mount rails_admin? Press <enter> for [admin] > admin
        gsub  config/routes.rb
       route  mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
           -  And you already set it up, good! We just need to know about your user model name...
           -  We found 'user' (should be one of 'user', 'admin', etc.)
           ?  Correct Devise model name if needed. Press <enter> for [user] > user
           -  Ok, Devise looks already set up with user model name 'user':
           -  Now you'll need an initializer...
           -  You already have a config file. You're updating, heh? I'm generating a new 'rails_admin.rb.example' that you can review.
      create  config/initializers/rails_admin.rb.example
NameError: uninitialized constant Rails::Application::Railties
irb(main):001:0> RailsAdmin::AbstractModel.all.map{|am| "'#{am.model}'" }.join(', ')
NameError: uninitialized constant Rails::Application::Railties
    from /Users/ernest.bursa/.rvm/gems/jruby-1.7.4/bundler/gems/rails_admin-3a64340da87a/lib/rails_admin/config.rb:206:in `models_pool'
    from /Users/ernest.bursa/.rvm/gems/jruby-1.7.4/bundler/gems/rails_admin-3a64340da87a/lib/rails_admin/abstract_model.rb:12:in `all'

@mshibuya
Copy link
Member

@swistaczek
Copy link

@mshibuya I updated to bleeding edge rails version (master) and I also tried to use dirty patch

Rails::Engine.class_eval do
  def railties
    @railties ||= self.class.const_get(:Railties).new
  end
end

but without any effect.

Gemfile:

gem 'rails', github: 'rails/rails'
gem 'rails_admin', git: 'git://github.com/swistaczek/rails_admin.git', branch: 'rails-4'

Running generator:

➜ git:(master) ✗ rails g rails_admin:install
           -  Hello, RailsAdmin installer will help you set things up!
           -  I need to work with Devise, let's look at a few things first:
           -  Checking for a current installation of devise...
           -  Found it!
           -  Looks like you've already installed it, good!
           ?  Where do you want to mount rails_admin? Press <enter> for [admin] > 
        gsub  config/routes.rb
       route  mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
           -  And you already set it up, good! We just need to know about your user model name...
           -  We found 'user' (should be one of 'user', 'admin', etc.)
           ?  Correct Devise model name if needed. Press <enter> for [user] > 
           -  Ok, Devise looks already set up with user model name 'user':
           -  Now you'll need an initializer...
      create  config/initializers/rails_admin.rb
NameError: uninitialized constant Rails::Application::Railties

@mshibuya
Copy link
Member

@swistaczek
Fixed by 08f15db.

@sferik
We're ready to release master as 0.5.0! 🚢

@novito
Copy link

novito commented Jun 27, 2013

Hi guys,

I see you have merged rails4 branch into master, but keep getting errors when trying to bundle install:

Gemfile looks like this:

gem 'rails_admin', github: 'swistaczek/rails_admin'

And error goes like:

Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    rails_admin (>= 0) ruby depends on
      rails (~> 3.1) ruby

    rails (4.0.0)

Any thoughts on this?

@davebrace
Copy link

@novito have you tried a bundle update rails_admin? When you have a github reference like that, you are locked into a specific revision I believe. If you run the bundle update it should update the revision lock to the latest commit.

@novito
Copy link

novito commented Jun 27, 2013

@davebrace interesting:

I did bundle update rails_admin, and I got

Could not find gem 'rails_admin'

I removed the Gemfile.lock, run bundle install and got:

Bundler could not find compatible versions for gem "coffee-rails":
  In Gemfile:
    rails_admin (>= 0) ruby depends on
      coffee-rails (~> 3.1) ruby

    coffee-rails (4.0.0)

Are you guys seeing something similar?

@novito
Copy link

novito commented Jun 27, 2013

Ok. I was pointing to 'swistaczek' fork instead of 'sferik'. The bundle install worked fine after changing that.

Sorry guys.

@wstan77
Copy link

wstan77 commented Jun 27, 2013

after writing 'bundle exec rake db:migrate' I get the following message

Admin does not respond to 'devise' method. This usually means you haven't loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb'

I have the version 4 of rails

@mshibuya
Copy link
Member

@wstan77 Your devise configuration is wrong. Not an issue with RailsAdmin.

@wstan77
Copy link

wstan77 commented Jun 28, 2013

I found and what was the mistake, thanks :)

@wstan77
Copy link

wstan77 commented Jul 1, 2013

Hi guys!.... I am a beginner in rails and when I enter my password I get the following error:

ActiveModel::ForbiddenAttributesError in Devise::RegistrationsController#create
ActiveModel::ForbiddenAttributesError

I have installed rails 4 and rails_admin however, in rails 3 does not give me any errors!

@mshibuya
Copy link
Member

mshibuya commented Jul 1, 2013

@wstan77 Please do not use the issue tracker for a support request.
Use StackOverflow instead.

@davidwparker
Copy link

Note that the wiki docs are really old. This page https://github.com/sferik/rails_admin/wiki/CarrierWave still uses attr_accessible. It would be nice to know what the current methodology for deleting an image is in Rails 4+. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests