Sunday, September 12, 2010

Re: [Rails] Re: Re: html input strings to database column integers

 
I am sorry....user_id is nested with game hash....so use params[:game][:user_id]
 
 
 
 def create
 
  @user = User.find(params[:game][:user_id])
  @game = @user.create_game(params[:game])
 
   if @game.save
     redirect_to user_game_path(@user, @game)
   else
     render :action => 'new'
   end
 end


 
On Mon, Sep 13, 2010 at 12:16 AM, Srikanth Shreenivas <srikps@gmail.com> wrote:
In the "create" method, there is nothing that links "user" and "game" together...that is causing the issue.
 
I am little rusty on exact syntax, but based on my rails code I could refer, I suggest trying out followings:
 
Based on your logs, user_id is nested within user hash, so i suggest you use params[:user][:user_id] in User.find.
Also, use the in-built create method to create game instance from user instance (Refer http://guides.rubyonrails.org/association_basics.html#belongs_to-association-reference).
 
 def create
 
  @user = User.find(params[:user][:user_id])
  @game = @user.create_game(params[:game])
 
   if @game.save
     redirect_to user_game_path(@user, @game)
   else
     render :action => 'new'
   end
 end
  


 
On Sun, Sep 12, 2010 at 11:59 PM, Keith Raymond <lists@ruby-forum.com> wrote:
Here is my games_controller:

class GamesController < ApplicationController
 def show
   @user = User.find(params[:user_id])
   @game = Game.find(params[:id])
 end

 def new
   @user = User.find(params[:user_id])
   @game = Game.new
 end

 def create
   @user = User.find(params[:user_id])
   @game = Game.new(params[:id])

   if @game.save
     redirect_to user_game_path(@user, @game)
   else
     render :action => 'new'
   end
 end

 def edit

 end

 def update

 end

 def destroy

 end
end

As you can see, I haven't even begun to fight with update or edit.
Updates to the games table will occur later with responses from a flash
document.

From my dev_log.  It shows that the fields I want are getting posted.
But Rails is not seeing them.

Processing UsersController#1 (for 127.0.0.1 at 2010-09-12 14:23:26)
[PUT]
 Parameters: {"user"=>{"game"=>{"num_of_enemies"=>"7",
"enemy_check_box"=>["0", "50", "0", "0", "30", "0", "0", "20", "0", "0",
"0"], "user_id"=>"1", "user_empire"=>"30", "difficulty"=>"10",
"selection_of_enemies"=>"2"}}, "commit"=>"Begin Game", "action"=>"1",
"_method"=>"put",
"authenticity_token"=>"SX7VfUzPm3SdzqFoKX4DQObQaHQLXSJudlNIfEGUt2Q=",
"id"=>"games", "controller"=>"users"}
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate