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 #2326

Merged
merged 18 commits into from
Sep 25, 2013
Merged

Rails 4 #2326

merged 18 commits into from
Sep 25, 2013

Conversation

seanlinsley
Copy link
Contributor

Hey everyone! Active Admin should now be ready for use with Rails 4. Previously you had to specify multiple gems to use the latest code on their repo, but now Active Admin is the only one that doesn't have an official release. For now, this is all you need to specify:

gem 'activeadmin', github: 'gregbell/active_admin', branch: 'rails4'

Note that Rails 4 introduces a new API for mass-assignment protection. You should use this pattern for every model:

ActiveAdmin.register AdminUser do
  controller do
    def permitted_params
      params.permit admin_user: [:email, :password, :password_confirmation]
    end
  end
end

If you have any troubles, please post here if it's something small, or otherwise open a new Issue.

Thanks to everyone who helped identify issues in #1963, and especially thank you to everyone who submitted code ❤️

@ashour
Copy link

ashour commented Jul 6, 2013

Hey guys,
Trying to work with AA on Ruby 4.0.0. Get this error when I try to create a new Admin User:

ActiveModel::ForbiddenAttributesError in Admin::AdminUsersController#create

@seanlinsley
Copy link
Contributor Author

That's because you need to define the attributes that are accessible:

ActiveAdmin.register AdminUser do
  controller do
    def permitted_params
      params.permit user: [:first_name, :last_name, :username, :age]
    end
  end
end

I'll add a commit that updates the app generator to auto-add this to the AdminUser file.

@ashour
Copy link

ashour commented Jul 6, 2013

Bizarre: When I do that, I get "can't be blank" validation errors for the email and password fields.

@seanlinsley
Copy link
Contributor Author

How is that bizarre? IIRC, those are validations that Devise adds in.

@ashour
Copy link

ashour commented Jul 6, 2013

The bizarre bit is that I'm inputting values and getting the validation errors.

@seanlinsley
Copy link
Contributor Author

Ah... The code I listed was wrong. It should be this:

params.permit admin_user: [:email, :password, :password_confirmation]

@ashour
Copy link

ashour commented Jul 6, 2013

That fixed it. Thanks @daxter. Much appreciated. So I guess the it's:

params.permit snake_cased_resource_name: [:array, :of, :symbols, :corresponding, :to, :input, :names]

to white-list params.

@seanlinsley
Copy link
Contributor Author

Yep. More info can be found here. But basically this whitelists certain param keys to be used in mass assignment.
Since the query string would look like this:

/admin_users/new?admin_user[email][email protected]

You have to whitelist that param like so:

params.permit admin_user: [:email]

@ashour
Copy link

ashour commented Jul 6, 2013

Perfect, thanks again.

@ashour
Copy link

ashour commented Jul 6, 2013

FYI I just noticed that for a relationship, you have to use the db field name e.g. if you have a Post resource that's modeled:

class Post < ActiveRecord::Base
  # includes id, title, slug, blurb, content, category_id db fields

  belongs_to :category
end

Then the app/admin/posts.rb resource file would be:

ActiveAdmin.register Post do

  # ...

  controller do
    def permitted_params
      params.permit post: [:title, :slug, :blurb, :content, :category_id]
    end
  end
end

Note category_id, not category.

Now does this mean that the parameter array in the params.permit white-list should include model db field names, and not form input names?

@seanlinsley
Copy link
Contributor Author

You should look at the HTML of the form. It most likely uses post[category_id]

@ashour
Copy link

ashour commented Jul 6, 2013

Yes, yes it does. Thank you for your patient clarification.

@seanlinsley
Copy link
Contributor Author

Just rebased this branch on master (aacd755 -> 54fb71c)

@lclemence
Copy link

I did everything you said above. And I have an issue with inheritance classes: Issue #2366

@diguage
Copy link

diguage commented Jul 29, 2013

I had the same question. Thanks a lot!

@seanlinsley
Copy link
Contributor Author

Just rebased this branch on master (a0d3873 -> a9949c1)

@seanlinsley
Copy link
Contributor Author

Just rebased this branch on master (a9949c1 -> ec3b7c3)

@conradwt
Copy link

@daxter It might be a good idea to add a section to the README which includes the Rails 4 specific setup.

seanlinsley and others added 9 commits September 20, 2013 10:20
For some reason, Formtastic checks if a constant is defined first, which doesn't play nicely with autoloading of custom inputs. This brings Formtastic's implementation back to pre formtastic/formtastic#783
Since our major dependencies now have official rubygems releases that
support both Rails 3.2 and 4.0, I'm making those new versions a
requirement in the gemspec.
@seanlinsley
Copy link
Contributor Author

Just rebased this branch on master (ac4918e -> ba2d10f)

@seanlinsley
Copy link
Contributor Author

@gregbell I'm working on merging this into master. The only real difficulty is gem version requirements. Looking it over, I'm tempted to remove version requirements for asset gems:

  s.add_dependency "arbre",               "~> 1.0"
  s.add_dependency "bourbon"
  s.add_dependency "coffee-rails"
  s.add_dependency "devise",              "~> 3.0"
  s.add_dependency "formtastic",          "~> 2.3"
  s.add_dependency "inherited_resources", "~> 1.3"
  s.add_dependency "jquery-rails"
  s.add_dependency "jquery-ui-rails"
  s.add_dependency "kaminari",            "~> 0.13"
  s.add_dependency "rails",               ">= 3.2", "< 4.1"
  s.add_dependency "ransack",             "~> 1.0"
  s.add_dependency "sass-rails"

Especially since these gems have their own version requirements for Rails, it should work out fine.

@hakanensari
Copy link
Contributor

Off topic: You can simplify the Rails version to "~> 4.0.0"

@seanlinsley
Copy link
Contributor Author

No, ~> 4.0.0 wouldn't support Rails 3.2

@hakanensari
Copy link
Contributor

👍

@seanlinsley
Copy link
Contributor Author

Meh, for now I'm going to go with that versioning scheme. It can always be changed later.

seanlinsley added a commit that referenced this pull request Sep 25, 2013
Conflicts:
	activeadmin.gemspec
	lib/active_admin/base_controller/authorization.rb
	lib/active_admin/dependency_checker.rb
@seanlinsley seanlinsley merged commit 85b9f81 into master Sep 25, 2013
@seanlinsley
Copy link
Contributor Author

Congrats everyone, 0.6.1 has been released so this branch has been merged into master! 💃

Note that while doing so I ran into a new bug: #2497

@twe4ked
Copy link

twe4ked commented Sep 25, 2013

Awesome. Thanks everyone who was involved in this.

@mindhalt
Copy link
Contributor

@daxter, you are my hero! 😻

@cpence
Copy link

cpence commented Sep 25, 2013

Hooray! Can't wait to see this cut into a new proper release. 🚢 👍

@hybridknight
Copy link

👍

@azlantaher88
Copy link

👍 Cant wait !!

@seanlinsley seanlinsley mentioned this pull request Oct 12, 2013
bru added a commit to 100Starlings/callme2 that referenced this pull request Nov 1, 2013
@hiveer
Copy link

hiveer commented Mar 31, 2014

When I done it as the instruction says, I got an error on bundle step: fatal: ambiguous argument 'rails4': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]' ...
So guys, What's wrong here?

@shekibobo
Copy link
Contributor

There is no longer a rails4 branch. Master is the current Rails3/4 compatible branch.

gem 'activeadmin', github: 'gregbell/active_admin'

@hiveer
Copy link

hiveer commented Mar 31, 2014

@shekibobo
Thanks so much.

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

Successfully merging this pull request may close these issues.