I have a taxonomy system for a Laravel application I'm working on, as we needed more flexibility than the usual category/tag systems. Taxonomy models look something like this:
id
name
While the topic models look something like this:
id
taxonomy_id
name
description
Projects then have a many-to-many relationship with topics.
Now, the project is using Nova for the admin, and I've registered the Topic and Taxonomy models in the usual way, so from the admin one can create a Taxonomy, and then create Topics within that taxonomy. However, that's not exactly the behaviour I'd ideally want. I'd prefer it if I could define a Taxonomy, then have that taxonomy dynamically appear in the admin.
For example, if I create a new taxonomy in the admin called Sectors, I'd then see Sectors appear as a registered resource. These would still be Topic instances under the hood, but would be presented as Sectors. If I then created a Type of Work taxonomy, that would then be added dynamically as a registered resource too.
After digging through the Nova docs I haven't found a way to achieve this in the admin. Can anyone suggest a possible route to achieve this?
Related
If I want to build a Rails app that has two different types of users, let's say one type is called players and the other one is owners, what is the best and most efficient approach to modeling the app?
Things to take into account:
There should only be one Login, but different Registration forms that Owners/Players can use.
Owners can have access to a control panel but Players cannot.
Owners cannot share any of Players capabilities, but both need to be able to perform Login/Registration.
I am not using Devise, so please do not suggest it.
Different Approaches I've considered:
Using cancancan gem, but it does not really seem to meet my needs in the sense that I am not looking to create a user/admin hierarchical approach but rather a if you're a Player, then you can see these pages and perform these actions but Owners cannot and vice versa. Almost like splitting the app in two. cancancan seems that it would treat Owners as "Players with extra privileges", not different privileges entirely.
Creating separate models with separate login and registration forms, which seems like a disaster waiting to happen. One small mixup between a Players table and the Owners table, especially with the primary keys, and that will be a world of trouble where people could end up logging in to the wrong accounts.
Creating a polymorphic or has_one relation toward an Account model, which so far, seems like the best way to probably go about it. If I created a polymorphic Account model, I can store different types of Players/Owners, but how could I compare login credentials against all types?
I had been trying to find something on this matter regarding how to map this out and was surprised to not find an information on how to do this without using Devise. If anyone has any good links they can point me to that also address this matter (without Devise), please leave them in your answer! Thanks.
I'd suggest one User class with a type attribute that determines whether the user is a Player or an Owner (single table inheritance). This way you keep the registration logic in one place but can customize the forms depending on the user's class.
There must be alternatives to cancancan that help with what you want to do, or you can implement helpers yourself:
def can_access_control_panel?
current_user.is_a?(Owner)
end
You have to have a way to separate one user from another. One way is to add an attribute to the User table so you can call current_user.role and it will return "owner" or return "player".
I have used Pundit gem in the past. It lets you define which controller actions the current user is allowed to access. So as you create resources for your application, you can add a policy that specifies who is allowed to that given resource. This is the repo to the application.
This answer might help you.
I am working for a medical project, where i hold so many modules like..
Regisration
Login
There are 2 types of users in the system:
Patient
Profile
Patient history
Appointments (also in doctor)
Prescriptions
Lab Reports
Doctor
Schedules
Appointments (also in patient)
Create Hospital
Can i make every user as a module in zend framework 2, or creating a single module and make every other functionality(appointments, schedules) as a controller.
Can anyone guide me..
As pointed out by AlexP in the comments this is not true at all.
First off no you shouldn't create modules for each of these users. These pretty much just types of Users using your system. I.e User Roles.
Now there various ways and modules that could achieve restrictions regarding those users I personally like BjyAuthorize. This uses zendframeworks ACL implementation with further improvements to the usability etc.
Within your BjyAuthorize configuration you just configure what each Role can see/access/edit etc. and you should be good to go.
I'm pretty new to Rails and wanted to do something along the lines of choosing a subset of objects in my Model. For example, I have a Project model and wanted to select some subset of projects based on some join table with another model, Organizations.
My initial thought was to create some helper method in projects_helper.rb that would perform the appropriate lookup on to determine which projects to return.
Another thought was to utilize scoping as described here (http://apidock.com/rails/ActiveRecord/Scoping/Named/ClassMethods/scope).
Both seem to functionally complete the objective, but what would be the best practice way of accomplishing this? Is there a key difference as to what can access each of these approaches?
Thanks!
Depends on the point of view of the question being "asked" by the query.
If you are asking for an Organization's projects, you might choose the Org first, then display organization.projects. Nothing fancy going on there beyond linking the models appropriately (organization has_many projects, project belongs_to organization) and having the organization_id as a foreign key in the projects table.
I'm not sure if a named scope would be appropriate if the Organizations in your system are a dynamic quantity. You don't want to have a named scope for each if the list of organizations changes all that often.
Rather than the typical one store app, where I (as a user) go and add products that one seller (the owner of the Spree app) is selling, what I want to do is to create an ecommerce site that has multiple vendors.
So you could see an overview of all vendors, and then you can buy multiple products from multiple vendors.
Does Spree allow me to customize it to that extent?
If so, are there any docs for that?
Thanks.
One approach (the one I used), is to add a 'vendor' Property to each item. Note - this approach assumes that each item is only sold by a single vendor. If you actually have a marketplace with various vendors competing to sell the same item, you'll need to do a similar thing by adding a 'vendor' OptionType, that is defined for each product Variant.
Each vendor (new model) is assigned a code that can be used when setting up your items (as either a property value, or multiple variant option values). When an order is placed, you can use a new OrderFulfillment model to track the various shipments that the various vendors will use to fulfill that order (one OrderFulfillment record per vendor in the order).
That's basically all the model changes you'll need. In the controller area, you'll need to modify the 'shopping cart' event machine sequence to handle the different vendor's shipping methods. And in the case of multiple vendors, you'll also need to present the user with a choice of vendor (think amazon marketplace).
How you handle your payments to various vendors was not part of my project, but shouldn't be too complex to add if needed.
Regarding links: You should be familiar with the basic Spree concepts which are discussed in the guide in general, and more specifically here. You will also need to make some internal modifications (new associations, modified controller behavior) which you can read about here.
I think you have a few options available for that.
Essentially, you want an e commerce app where users can sign up and list their own products, and then have a user profile page where someone can look and see just that user's products, right? Some people call this multi-tenancy, and if you do a google search you will soon find this spree extension: multi-tenant
I am looking to do the same thing as you, and I'm a bit wary of multi tenant because I would have to roll back to Spree 2-2 stable (I'm currently on 2-3).
The previous answer here suggests that you should create a new model called Vendor. I would say why not just update your already existing user model to become a vendor?
What I'm suggesting is simply creating an association between the User model and the Spree::Products model. This way you can scope products to individual users and create profile pages without the complexity of adding new, foreign models and/or different admins for each user. All of the spree methods are already attached to your User class, so I would think a simple belongs_to/has_many association would work. Haven't tested this at all, but that's what my thinking is.
Consider a typical social networking website, which has more or less the following models:
User
Blog, Posts
Forums, Topics, Responses
Wiki, Pages
....
....
I want to introduce a model called Site/Space where each User can have one or many sites/spaces. And I want to provide a way for the Site owner to select many features (or call it apps/tools).
Whats the best way to design this model - so called feature/app/tool?
Note: In many cases each feature may not be the same as corresponding model. Lets consider blog feature, by enabling the Blog feature, I should be able to associate (some how) that the corresponding site has access to both Blog & Post, (another example) by enabling Forums feature, I should be able to associate the site has access to not only Forum, but also Topic & Response models. I need these checks so that I could define a before_filter to check if a particular site has access to the content or not.
I looked at some open source rails applications that have this kind of on demand features, but by looking at the form attributes, it looks like they have has_blog, has_post,... fields tucked in the Sites table, in my situation it may not work as the number of these models may grow. Do you still think that adding these boolean fields in the Sites table is the best approach?
polymorphic associations, has_many :through, and/or has_and_belongs_to_many sound like the building blocks to your solution. I'd look into them.
Define a many-to-many relationship between an Apps and a Sites table in your database.
Apps
AppID
Name
...
Sites
SiteID
UserID
...
SiteApps
SiteID
AppID
SELECT AppID FROM SiteApps WHERE SiteID=...
See also SQL: Many-To-Many table AND query