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 7516719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:13:22+00:00 2026-05-30T01:13:22+00:00

I first learned about Data, context, and interaction (DCI) through this blog post .

  • 0

I first learned about Data, context, and interaction (DCI) through this blog post. Fascinated by the concept, I endeavored to build it in to my next Rails application. Since DCI works in tandem with MVC, I thought it wouldn’t be too hard to make the API RESTful at the same time. So I made a RESTful resource, Report and extend it with various contexts. The way I implemented contexts in Rails was by creating a directory, /app/contexts/, for modules which extend the controller actions. So my reports_controller.rb looks like this:

class ReportsController < ApplicationController
  before_filter :only => :new do |c|
    c.switch_context("submission")
  end

  # GET /reports
  def index
    @context.report_list
  end

  # GET /reports/1
  def show
    @context.display_report
  end

  # GET /reports/new
  def new
    @context.new_report
  end

  # GET /reports/1/edit
  def edit
    @context.edit_report
  end

  # POST /reports
  def create
    @context.create_report
  end

  def update
    @context.update_report
  end

  # DELETE /reports/1
  def destroy
    @context.destroy_report
  end

  protected

  def switch_context(context_name)
    session[:context] = context_name
    context = session[:context].camelize.constantize
    @context ||= self.extend context
  end
end

And in the application_controller.rb I set the context with a before_filter:

class ApplicationController < ActionController::Base
  before_filter :contextualize
  protect_from_forgery

  protected

  # Sets the context of both current_user and self
  # by extending with /app/roles/role_name
  # and /app/contexts/context_name respectively
  def contextualize
    # Extend self (ActionController::Base) with context
    if session[:context]
      context_class = session[:context].camelize.constantize
      if current_user.allowed_contexts.include?(context_class)
        context_class = current_user.context if context_class == Visiting
      else
        context_class = Visiting
      end
    else
      context_class = current_user.context
    end
    @context ||= self.extend context_class
  end
end

Notice I extend current_user with a Role in addition to the controller context.

Here’s how it works:

  1. A user logs in.
  2. The user’s role is RegisteredUser.
  3. RegisteredUser‘s default context is Search (as defined in /app/roles/registered_user.rb).
  4. Inside the Search context, the user can only view published reports.
  5. The user presses the “create new report” button and the context is changed to Submission and stored in the current_user‘s session.
  6. The user then proceeds to submit a report through a multi-step form.
  7. Each time the user saves the report by stepping through the form the /app/contexts/submission.rb context handles the action.

The are several other contexts (review, editorial, etc.) and roles (co-author, editor, etc.).

So far this approach has worked well for the most part. But there is a flaw: when a user opens multiple browser windows and changes contexts in one of them, all of the other windows will be in the wrong context. This could be a problem if the user is in the middle of the multi-step form and then opens a window in the Search context. When he switches back to the form and hits “Next”, the controller will perform the action defined by the Search context instead of the Submission context.

There are 2 possible ways around this that I can think of:

  1. Namespace the Report resource with the context name. So the user would visit URL’s such as /search/reports and /submission/reports/1. This doesn’t seem RESTful to me and I would rather keep the URL’s as clean as possible.
  2. Put the context name in a hidden field. This method requires developers to have remember to put the hidden field in every form on the site, and it doesn’t work for GET requests.

Are there any other ways around this problem, or better overall implementations?

I know of this project, but it’s too limited for our needs.

  • 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-30T01:13:24+00:00Added an answer on May 30, 2026 at 1:13 am

    If you want to allow for multiple contexts then obviously you must put the information which determines the current context in some storage which is not shared between tabs. Sessions, as implemented in Rack/Rails, use cookies, and cookies are shared between tabs.

    Just put the context into something, that is not shared. How about a context=viewer URL parameter?

    To talk REST I think it is arguable whether or not a resource is the same or not in different contexts. One could argue that a report for a “Visiting” user is different from a report for an “Administering” user. In that case a RESTy approach would probably namespace the requests (which again puts the context into the URL), e.g. /visiting/reports/1 vs /administering/reports/1.

    And a third way to put the context into the URL would be to use it as part of the domain name.

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

Sidebar

Related Questions

Everything is an object was one of the first things I learned about Ruby,
I'm new to MySQL, and just learned about the importance of data normalization. My
I've been intrigued by all the android world since I first learned about it
So this is my first real Ruby on Rails project. I've learned my lesson
One of the first things I learned in C++ was that #include <iostream> int
One if the first things I learned when I started with C# was the
First, let me say that I'm a complete beginner at Python. I've never learned
First, thanks for all the help I've received so far from StackOverflow. I've learned
I am a newbie and just learned that if I define say package my.first.group.here;
When I first started programming, I wrote everything in main. But as I learned,

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.