Topic: Game in Rails

Hi everyone.

I am trying to build an app in rails like a game. It gives the user a hint and asks the user to guess the word. If the user guesses the word he becomes a winner. Else he tries more.

Any idea how to do that?


Re: Game in Rails

Sounds like a page with a hint, a text field and a button.
You'll need a controller to check the user's guess and reroute the user based on the result, i.e., if the user wins then show a success page, if the user fails then show them the initial form to try again.

Start with phase 1, something lite:
1) Create a guesses controller with new and create actions.
2) Create the form view, with the hint, the text field tag and the submit button.
3) In the controller, capture the user's input in the create action:

def create
  users_guess = params[:guess]
  if users_guess == "the Answer" # hardcode for now, dynamic in phase 2
    render :text => "You win!"
    flash[:notice] = "Try again"
    render :action => "new"

Hopefully that will get you started.

Last edited by pullmonkey (2011-07-27 13:25:57)

Re: Game in Rails

This one helped a lot but i am having difficulties with the form. When i submit it i always win. I dont know what i do wrong. Any how can i validate the text field of the word if i dont have a model?

Re: Game in Rails

another question, how do i route this?

Re: Game in Rails

Ah, sorry about that, I had a