Question

Need some tips on how to achieve.

Normally we would do this for scaffold:

rails g scaffold User email:string password_hash:string password_salt:string (and exit)

However, due to the complexity of what I want to achieve in mind, thus the following:

  • Admin users, where "Admin" is the namespace

    rails g scaffold Admin::User email:string password_hash:string password_salt:string (and etc)

  • Items, where "Application" is the namespace. Items is a model that will be access by different namespaces.

    rails g scaffold Application::Item name:string cost:float quantity:integer

So, obviously "Admin" namespace is used for Administrators to login and they could manage items.

However, I'm creating the rails app in such that I has multiple login for different application such as Namespaces(again) - Application1 - Application2

So you would expect the main page of each Application to be below as respectively:

http://my.railsapp.com/application1/index
http://my.railsapp.com/application2/index

However, I want to achieve scaffolding, thus Application::Item can be used in any namespace like Application1::Item.

Example would be in my controller(application_a/items_controller)

@items = Application1::Item.all

And in my views, like rails scaffolding

...
 <% @items.each do |item| %>
  <tr>
    <td><%= item.email %></td>
    <td><%= link_to 'Show', item %></td>
    <td><%= link_to 'Edit', edit_application1_item_path(item) %></td>
    <td><%= link_to 'Destroy', item, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  </tr>
<% end %>
...

To explain my reasons. I would like Admin to create, and edit any field for Items. Application1 to edit the cost or quantity and finally Application2 to update only the quantity. Ofcourse, its more to just restrictions, but to put it simply is different application utilising on the same data model.

Thanks.

Was it helpful?

Solution

Scaffolding is for most common cases. If it can't meet your need on customization, then don't use it, create models and controllers separately. No need to waste time on digging that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top