Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:34:12+00:00 2026-05-26T13:34:12+00:00

I wondering is there a way to represent model differently (or probably control access

  • 0

I wondering is there a way to represent model differently (or probably control access on fields level) depending on it’s (model instance) state and controller using it.

Example:

Imagine we have an Order model with product_id, count, price and status fields.
status could be one of: :new, :confirmed, :accepted, :cancelled, :delivered and :closed.

Application can access Order from, say, two controllers CustomerOrdersController and SellerOrdersController. So, CustomerOrdersController could create and edit orders. But able to change only count field. On the other hand SellerOrdersController could edit orders. But able to change only price field. I.e. it would be great if instance of Order class that CustomerOrdersController working with have no price= method. Same for count=(product=) and SellerOrderController.

Further more set of columns permitted to edit depends on status field (probably work for some state machine).

So, the question is: how would you do this in your app?

PS

I think about some ActiveModel proxy objects for ActiveRecord instances, but do not know actually will it work or not. Consider:

class CustomerOrderProxy < ActiveModel::Base end
class SellerOrderProxy < ActiveModel::Base end

class Order < ActiveRecord::Base
  def wrap_proxy(controller_user)
    controller_user == CustomerOrdersController ? CustomerOrderProxy(self) : SellerOrderProxy(self)
  end
end

Another approach would be to do tons of checks and params validations inside controller actions, but I do not want to. I believe in “Fat model – skinny controller” 🙂

PPS

I know that ruby have plenty state machine plugins, but AFAI understand they define only transitions, not method set (i.e. representation) of the object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:34:13+00:00Added an answer on May 26, 2026 at 1:34 pm

    Looks like I’ve found appropriate solution: in Ryan Bates’s screencast Dynamic attr_accessible

    Update:
    In Rails 3.1 update_attributes(params[:order], role) could be used. Check out rails api. Though it cannot be used to change access control according to object’s state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering if there is a way in Spring to have a parent controller:
I was wondering if there is way to open another page using a Modal
I was wondering is there a way in PHP that you could tell where
I am wondering is there a way to render a partial view in the
I am wondering is there any way we can test the font size/color of
I think I understand unit testing. But I was wondering: is there a way
Wondering if there is any way to get the lambda expressions that result from
Just wondering if there is any way (in C) to get the contents of
Just wondering if there is any way to get the NS records in C#.
was wondering if there is a way to make superfish using jquery ui theme

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.