I can't insert to my database rails
i can't insert to my database whats is my problem?
it's bowling game and i have two tables with name "Player" and "Result"
<%= form_for player_new_path(@player) do |f|%> <div class="text_field"> <p> <%= f.label "Spelare namn" %> <%= f.text_field :name %> </p> <p> <%= f.submit "Lägg till en spelare"%> </p> </div>
Controller def create @player = Player.new(params[:players]) if @player.save redirect_to players_new_path else render :action => "new" end end
Not work :/ my model:
class Player < ActiveRecord::Base # attr_accessible :title, :body belongs_to :result end
and my migrations:
class CreatePlayers < ActiveRecord::Migration def change create_table :players do |t| t.string "name" t.references :results t.timestamps end
Check your params hash. I bet the key isn't 'players', it's probably 'player'.
@player = Player.new(params[:players]) should probably be @player = Player.new(params[:player]) (You are getting a single player as a param)
Otherwise, what error are you getting