-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
How to use with namespaced models. #179
Comments
I'm looking for something similar. I want to create a set of name spaced models that extend my application models so I can add in Admin specific methods and not pollute my application models. |
I did some digging into the code.. the Resource Resolver uses the controller_path to create the class name.. for my Platform::User it was admin_users which in turn becomes User.. making it platform_users doesn't help as that becomes admin/platform_users and in turn PlatformUser not Platform::User.. |
feels like it's going to be quite a change to make this work. . every where I make a small change it leads down a path to some magic somewhere else in the gem. make a different change and some other magic fails. there's far too many assumptions that the classes do not have a namespace.. I will continue and see if I can get it working.. |
I'm at a point where I've modified the resource resolver for the namespaced class. I.e. Currently working on getting the I'l let you know if I get anywhere. I'm struggling with |
BTW I had the named spaced model working though not happy with the implementation at the moment.. feels quite hackish.. (i have committed it to my fork last Friday).. Haven't tried any has many yet.. but will today.. I'm going to end up needing to handle namspaced models with nested forms.. so I'm sure I'll tackle a few things.. hoping this works.. tired of fighting with activeadmin.. :-) |
@tomgatzgates I'd love to see your modified I think the solution might involve changing up the DASHBOARDS = [
"users",
"store/line_items",
"store/orders",
"store/products",
] I believe that |
@gpinkham can you post a link to your fork? Interested in how you got it working! |
funny thing.. just as your response came to my inbox I was experimenting with changing the dashboard manifest and the code in the routes to handle the names like as 'foo/bar'.. so my code that's in the repo does not have that. I just started to switch because I also use papertrail and its hard to determine in paper_trail_versions which part is the namespace and which part is simply camelcase to underscore.. never realized how much of a pain that ambiguity was.. here's my repo.. https://github.com/gpinkham/administrate so I had forgotten to hit enter earlier today on this. updating now as I removed most of the code from Friday.. going with the 'namesapce/model' in the dashboard manifest and changing the code that administrate put into the routes.rb worked for me (plus a change I made on friday to a path lookup.. need to find that). I think I will redo this on a fresh fork and update the routes generator as well.. then submit a pull request (need to add tests too!) |
@gpinkham that sounds great, thanks! looking forward to seeing your solution. |
great to hear that I'm not the only (present) person needing namespaced support - @gpinkham how is your branch looking ? thanks. |
@jshow sorry.. I have been off on other work. One of the guys on my team has been trying to get our activeadmin code ported over to administrate.. I'll admit neither of us are happy with some of the "hacks" we had to do to get things to work.. the namespace thing was easy compared to dealing with an engine.. Once I can wrap my head around everything I will see what I can do to contribute the work back.. |
thanks @gpinkham - I've decided that Administrate is too raw at this juncture - I'll be starting with activeadmin until it evolves. cheers |
I am trying to achieve the same. I am using pow have an api endpoint set as (following http://apionrails.icalialabs.com/book/frontmatter): namespace :api, defaults: { format: :json },
constraints: { subdomain: 'api' }, path: '/' do
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
resources :users, :only => [:index,:show, :create, :update, :destroy]
devise_for :users, :controller => {:users => 'users'}
end
end I can navigate to /admin/users/1/edit and it displays the form correctly, but when I hit save it gives the error "No route matches [POST] "/admin/users/1" Any suggestions? |
@tanaylakhani I think you're seeing something different than the rest of this thread... Would you mind creating a new issue for it? Thanks! |
Is this still on track for v0.1.3? |
@erickreutz, most of the features for v0.1.3 got pushed back to v0.1.4 - we've changed up v0.1.3 to be mostly generator improvements. We've started tracking development progress with GitHub's milestones - you can see this one is in v0.1.4. |
I'm also interested in seeing a workaround for using namespace models, specifically for use with acts_as_taggable_on gem. Did you end up making it work @gpinkham ? |
+1 |
With a few tweaks to @gpinkham's fork I got namespaced models working well enough for my purposes: https://github.com/micapam/administrate/commits/feature/namespaced-models I haven't touched the generators, though. If I get time I will do so, but in the meantime (in my project) I did the following to get it working for me:
namespace :admin do
DashboardManifest::DASHBOARDS.each do |dashboard_resource|
if dashboard_resource =~ /\//
ns, res = dashboard_resource.split '/'
namespace ns do
resources res
end
else
resources dashboard_resource
end
end
root controller: DashboardManifest::ROOT_DASHBOARD, action: :index
end |
Did this get pushed back from v0.1.4 to v0.1.5? |
Hey Guys, I'm trying to get administrate going and am having trouble with models that have Papertrail. Whenever I try to "edit" a model that has papertrail I get the error:
I'm also using a gem "Payola" when I try to create/edit models with Payola attached I get the error:
I believe these are both namespacing errors (from reading the thread above). Does anyone have any insight on how to fix these errors? Thanks! |
Are namespaced models still unsupported? I'm having the same issue with one that lives inside an engine (and is therefore namespaced). |
@Graysonwright - Is this still an issue, as I'm hitting the bug? |
@micapam - Thanks for the info! Any chance you could provide an example of "(2)put a string rather than symbol into dashboard manifest"? |
@seanfcarroll - Sorry, I'm not following? |
@ACPK did you work out how to use this fork? |
@seanfcarroll - Anything? |
I gave up... Sorry am thinking of rolling my own admin panel
|
Same problem here with papertrail. |
I'm running into this problem as well... name-spaced models aren't fully supported with this gem. |
@nickcharlton We should try to address this one in an upcoming release |
@carlosramireziii - I figured out a place to start. It looks like if you don't rely on the generators and make a Dashboard and Controller with a namespace and place them in the directory structure Rails autoloader expects, you end up with 500 errors and helper methods would look like this: If you look at def resource_name
@resource_name ||=
dashboard.class.to_s.scan(/(.+)Dashboard/).first.first.parameterize(separator: '_')
end My simple proof without trying a ton of use cases: [4] pry(main)> 'Blog::Post'.underscore
=> "blog/post"
[5] pry(main)> 'Blog::Post'.parameterize(separator: '_')
=> "blog_post" NOTE: The tricky part here is Rails framework version support. I also had to override the default <ul class="sidebar__list">
<% Administrate::Namespace.new(namespace).resources.each do |resource| %>
<li>
<%= link_to(
display_resource_name(resource),
[namespace, resource.to_s.parameterize(separator: '_')],
class: "sidebar__link sidebar__link--#{nav_link_state(resource.to_s.parameterize(separator: '_'))}"
) %>
</li>
<% end %>
</ul> In case it helps, here are my routes, dashboard, and controller for the #routes namespace :admin do
resources :admin_users
namespace :blog do
resources :posts
end
root to: "admin_users#index"
end #app/admin/blog/posts_controller.rb module Admin
class Blog::PostsController < Admin::ApplicationController
end
end #app/dashboards/blog/posts_dashboard.rb require "administrate/base_dashboard"
class Blog::PostDashboard < Administrate::BaseDashboard
#normal stuff
end |
…veRecord/Model classes. This allows one to reference ActiveModel’s route values (route_key, singular_route_key) when generating Polymorphic URLs.
@carlosramireziii - made a ton of good progress on this one. I learned the real problem going on inside of Administrate's code is its reliance on ActiveSupport::Inflector helper methods. I will tidy up the branch I made on my company's fork and submit it back for review. The gist is that I allowed Administrate to expose ActiveModel::Name objects, which allows using |
Isn't #688 pretty much what is needed to support namespaced models? |
@danielricecodes Thanks for the detailed response! Would love to see your approach after you've cleaned up the branch. To @klaseskilson's point, does your approach differ from #688? From skimming that PR, it seems to solve the problem by changing attribute names from symbols to strings and then using WDYT? |
Sure thing. My approach is slightly diffferent than #688. I prefer to use ActiveModel::Name to get the correct display and route names of the ActiveRecord models that Pages wrap around. There may be a better way to specify a model for a given page than trying to infer it from routes also. I'm thinking about a more wholistic approach that can replace Administrates reliance on routes. I have the gem installed locally and have been hacking away. Give me a bit and I should have something. Then we can compare my solution with #688 and see which is preferred. Either way, a good discussion about code will ensue :) |
…tiveModel::Naming to get at the correct resource names. It should still be possible to specify a resource here, instead of inferring it form the Dashboard class name.
The #688 PR supports both symbols and strings for attribute names. In addition the PR have changes for generators to support namespaced models. I will be glad to hear feedback/ideas and to combine efforts to solve the issue. |
I'm going to close this as #871 has been merged. Please open another issue if we've missed something! |
I have a user model that lives in Platform::User.. I ran the generator with administrate::dashboard Platform::User and this created a user_dashboard.rb and a users_controller.rb.. when I try to go to the users page in admin it fails saying
it points to this line in the controller:
I tried to remove the Platform:: from the controller and dashboard file but that just produced a similar error but this time saying User was an uninitiatized constant.
thanks!
Gary
The text was updated successfully, but these errors were encountered: