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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:29:50+00:00 2026-05-31T12:29:50+00:00

I am using Rails 3. I was coding a controller very verbose. So i

  • 0

I am using Rails 3. I was coding a controller very verbose. So i am trying refactoring the controller.

I coded a class called ProductMaker which make a product and modify session (product task for wizard form as current_step, if the request is a refresh, etc)

This class has method that receiving session as parameter, modify and then return this new session.

Controller action:

  def new
    #INITIALIZE CODE
    session[:refresh] ||= SortedArray.new [1]
    #...MORE CODE
  end

    def create
     #...MUCH CODE
     unless Utilities.is_refresh(session[:refresh])
        #...more code
        session = ProductMaker.some_method_which_return_session(session) #KEY PROBLEM LINE
        #...more code
     end
     #... MORE CODE
    end

My ProductMaker class in lib folder:

class ProductMaker

def self.some_method_which_return_session(session)
 session[:any_key] = "some value"
 return session
end

end

However when I write the KEY PROBLEM LINE the session is a nil value. If i comment this line the session is a ActionDispatch::Session::AbstractStore::SessionHash.

Which could be the problem?
How could i refactoring controller logic, that modify many session keys and ‘fill’ a model depending the session values, to model/class ?

UPDATE:

I am reading about binding in ruby.

How could modify the session using bindings and eval method?

If you have other ideas, please post your answer.

Thanks in advance

  • 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-31T12:29:51+00:00Added an answer on May 31, 2026 at 12:29 pm

    Finally I use bindings.

    For example:

    class SessionManager
    
    self.update(session, binding)
     eval "#{session} = 0", binding
    end
    
    end
    
    class SomeController < ApplicationController
    
    def foo_action_1
      session[:refresh] = 1
    end
    
    def example_ajax_modify_session
       a = session[:refresh] == 1 #true
       SessionManager.update("session[:refresh]", binding)
       b = session[:refresh] == 1 #false
       a == b #false because a == 1 and b == 0
    end
    

    I had to modify and manage many session values so before I has a very verbose controller.
    Now I could refactoring this logic to model.

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

Sidebar

Related Questions

I'm coding a Rails project in a Windows environment and using Eclipse (with the
Using Rails v2.1, lets say you have an action for a controller that is
When using Rails date_select with :prompt => true I see some very strange behavior
I am using Rails 2.3.5. Class User < ActiveRecord::Base has_many :phones end class Phone
I am making a game for Android and using Rails for server coding, and
I'm experiencing a very strange problem with Rails and ajax using jQuery (although I
I want to improve my Rails coding productivity using Textmate. Obviously, shortcuts (whether native
I'm using rails, but doing all my Javascript unobtrusively using jQuery in application.js .
I am using Rails 2.3 and I decided to provide support for JSONP. Created
I'm using rails 2.3.4 When I execute rake db:test:prepare the id field created is

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.