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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:04:18+00:00 2026-06-17T16:04:18+00:00

So I have some data that gets pulled from another rails app in a

  • 0

So I have some data that gets pulled from another rails app in a controller lets call it ExampleController and I want to validate it as being there in my model before allowing the wizard to move to its next step and I can’t quite figure out how I should be doing it (I know that getting this data directly from the controller into the model violates MVC I am looking for the best workaround to get my data from the controller) . The data must come from the controller as the methods for getting it are contained in ApplicationController however I could do this in the Awizard controller if this is easier. (Also I cannot use a gem)

Please offer some kind of suggestion to the problem and not an explanation of why this is not the correct way to do things I realise that already but cannot do it another way.


The Example Controller

should this instead render the data then check it isn’t blank elsewhere?

class ExampleController < ApplicationController

  def valid_data?            
    data = #data could be nil or not
    if data.blank?
      return false
    else
      return true
  end

end

My Model – (models/awizard.rb)

How do I use the valid_data? method from the example controller? in my validation here.

class AWizard
include ActiveModel::Validations
include ActiveModel::Conversion
include ActiveModel::Dirty
include ActiveModel::Naming

#This class is used to manage the wizard steps using ActiveModel (not ActiveRecord)

attr_accessor :id
attr_writer :current_step  #used to write to current step
define_attribute_methods [:current_step] #used for marking change

validate :first_step_data, :if => lambda { |o| o.current_step == "step1" };

def first_step_data
  #What should i put here to check the valid_data? from the examplecontroller
end

def initialize(attributes = {})
   attributes.each do |name, value|
     send("#{name}=", value)
   end
end

def current_step
  @current_step || steps.first
end

def steps
  %w[step1 step2 step3] #make list of steps (partials)
end

def next_step
  current_step_will_change! #mark changed when moving stepped
  self.current_step = steps[steps.index(current_step)+1] unless last_step?
end

def previous_step
  current_step_will_change! #mark changed when moving stepped
  self.current_step = steps[steps.index(current_step)-1] unless first_step?
end

def first_step?
  current_step == steps.first
end

def last_step?
  current_step == steps.last
end

def all_valid?
  steps.all? do |step|
    self.current_step = step
    valid?
  end
end

def step(val)
  current_step_will_change!
  self.current_step = steps[val]
end

def persisted?
  self.id == 1
end

end

Or do I need to add this to this view?

(/views/awizard/_step1.html.erb)

<div class="field">
  <%= f.label 'Step1' %><br />
  #This is the step I want to validate
</div>

  • 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-06-17T16:04:19+00:00Added an answer on June 17, 2026 at 4:04 pm

    I maybe have misunderstood the question since my answer is simple. However here’s a solution that doesn’t resort to metaprogramming, but to the fact that Wizard (the class not objects it creates ) is a singleton/constant.

    class ExampleController < ApplicationController
    
      def valid_data?            
        data = #data could be nil or not
        result = data.blank?
        Awizard.valid_data= result
        result
      end
    
    end
    
    class Wizard
      cattr_accessor :valid_data
    
    
      def valid_data?
        self.class.valid_data
      end
    end
    

    If course ExampleController#valid_data must have been called before you play around with a Wizard passing step_one.

    UPDATE:Reasoning about the global state problem

    (raised by @Valery Kvon)

    The argument is that Wizard is global to the application and that @wizard instances will be dependant on a global state and are therefore badly encapsulated. But Data, coming from another site, is gloabl in the scope of your app. So there’s no mismatch with Wizard beeing the one holding the data. On the contrary it can be considered as a feature.

    One example. Wizards magic is only efficient at full moon.
    Application SkyReport sends data :

    :full_moon => true
    

    It affects all wizards in stage 1 if they need to go on step2 of their power. Therefore relying on the global state of Wizard.valid_data? is exactly what we want…

    However if each wizard has a personal message coming from Gandalf’s application, then we’ll want to inforce the invocation of Gandalf’s data but then the solution is even simpler :

    # in example_controller.rb
    before_filter :set_wizard_data, :only => [:create, :update]
    ....
    def set_wizard_data
      @wizard = Wizard.find params[:id]
      @wizard.valid_data= valid_data
    end
    

    But this again implies that Gandalf.app knows (something of) the @wizard and from how the problem is presented, data coming from the other site is pretty agnostic !

    The issue here is that we don’t know enough about the app, its requirements and underlying logic to decide what’s good or not…

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

Sidebar

Related Questions

I have a Silverlight 5 app that gets some data from a couple Sharepoint
I have a view controller that gets presented modally and changes some data that
If have a piece of code that gets some data from a sql database
For example I have a mysql query that gets some data. Then runs another
Say I have an object that gets some data from HttpPost and some from
I have some data that gets pulled out of a database and mapped to
I have an activity that gets some data from the internet in background while
I have a list that gets filled in with some data from an operation
I have a query that gets some data from a DB and I save
This is driving me crazy. I have a PHP script that gets some data

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.