Let me preface this by saying that I am very new to Ruby and Ruby on Rails, and have been unsuccessful in finding a clear demonstration of translating a working Ruby program to a web application powered by Rails.
Ruby Part: I have a simple class that allows a user to create a "stick" on which she can set an ant to any open inch spot, whose direction is randomized to move up/down. The user can then call a run command and see the ants as they move up or down the pole until the ants fall off either end. The user can then check the minimum and maximum times it takes an ant on the pole to fall off of it.
Rails Part: Because the output of this program can changed depending on the initial directions of the ants, I do not see a need to employ a database over many instances.
Questions: Should my model class hold all of the code I have already written? If I want to build a simple webpage that allows a user to create a stick, the array of which is then displayed and continually updated, and then add the name and location of each ant, how (and from where) would the methods I had written be called upon?
I'm probably completely wrong, but I suspect my code should be in the models package, and the calls to the methods I created will be in the controller. That would mean that I should make sure that the new method within the controller class takes in an integer (for size). I should also write a new method that creates and sets the ant, and takes in a string and integer (also in the controller).
The code would look like:
def new(size)
@marchingant = Marchingant.new(size)
respond_to do |format|
format.html # new.html.erb
format.json { render json: @marchingant }
end
end
def createAndSet(loc, name)
@marchingant.createAndSet(loc, name)
end
(The methods within the model class validates the input) Thanks for your help!