I have a form in wich I can succesfully add someone to my db.
When I come to my list page I kan see everyone in that list so far so
good.
when I click on a member I can see the member in detail but the
"ploeg"
part is not giving me the info from the db back and it puts instead for
a second time "ploeg" example
Original input
naam: Paul
Achternaam: Pietersen
Score:9
Ploeg: J (can be empty or P or SR
geslacht: M/F
when I select this player to see the details after creation I get this.
naam: Paul
Achternaam: Pietersen
Score:9
Ploeg: ploeg
geslacht: M/F
when I want to edit this member I get the correct info back like this
naam: Paul
Achternaam: Pietersen
Score:9
Ploeg: J (can be empty or P or SR
geslacht: M/F
this is my controller
[code]
class PlayersController < ApplicationController
def index
list
render :action => ''index''
end
def list
@player = Player.find(:all)
end
def all_sorted
@heren=Player.heren
@dames=Player.dames
end
def score_sn
@senior=Player.sr
end
def score_jr
@junior=Player.junior
end
def score_p
@pupil =Player.pupil
end
def score_top
@man =Player.topm
@vrouw=Player.topv
end
def new
@player = Player.new
end
def create
@player = Player.new(params[:player])
if @player.save
flash[:notice]=''Speler is met succes toegevoegd''
redirect_to :action =>''list''
else
render :action => ''new''
end
end
def show
@player = Player.find(params[:id])
end
def edit
@player = Player.find(params[:id])
end
def update
@player = Player.find(params[:id])
if @player.update_attributes(params[:player])
flash[:notice] = ''de speler is met succes bijgewerkt.''
redirect_to :action => ''show'', :id => @player
else
render :action => ''edit''
end
end
def destroy
player.find(params[:id]).destroy
redirect_to :action => ''list''
end
end
[/code]
this is the edit.rhtml
[code]
<h1>Wijzigen van speler: <%= @player.naam -%></h1>
<% form_tag :action => ''update'', :id => @player do
%>
<%= render :partial => ''form'' %>
<%= submit_tag ''Edit'' %>
<% end %>
<%= link_to ''Show'', :action => ''show'',
:id => @player %> |
<%= link_to ''Back'', :action => ''list''
%>
[/code]
de show rhtml
[code]
<h1><%= @player.naam %></h1>
<p><strong>Naam: </strong> <%= @player.naam %><br
/>
<strong>Achternaam: </strong> <%= @player.achternaam %><br
/>
<strong>Score:</strong> <%= @player.score %><br />
<strong>Ploeg:</strong> <%= @player.ploeg %> <br />
<strong>Geslacht:</strong> <%= @player.geslacht %>
</p>
<%= link_to ''Edit'', :action => ''edit'',
:id => @player %> |
<%= link_to ''Back'', :action => ''list''
%>
[/code]
de _form.rhtml
[code]
<%= error_messages_for ''player'' %>
<!--[form:product]-->
<p><label for="player_naam">naam</label><br/>
<%= text_field ''player'', ''naam''
%></p>
<p><label
for="player_achternaam">achternaam</label><br/>
<%= text_field ''player'', ''achternaam''
%></p>
<p><label
for="player_score">score</label><br/>
<%= text_field ''player'', ''score''
%></p>
<p><label
for="player_ploeg">Ploeg</label><br/>
<%= text_field ''player'', ''ploeg''
%></p>
<p><label
for="player_geslacht">Geslacht</label><br/>
<%= text_field ''player'', ''geslacht''
%></p>
<!--[eoform:player]-->
[/code]
the model is this
[code]
class Player < ActiveRecord::Base
validates_presence_of :naam, :achternaam, :score, :ploeg, :geslacht
validates_numericality_of :score
@@ploegen={ ''P'' => ''pupil'',
''J'' => ''junior'', ''SR''
=> ''senior''}
def to_s
sprintf(" #{naam} #{achternaam} - #{score} ")
end
def self.heren
Player.find(:all, :conditions =>{:geslacht =>"M"})
end
def self.dames
Player.find(:all, :conditions =>{:geslacht =>"V"})
end
def ploeg
@@ploegen = :ploeg
end
def self.sr
@senior = Player.find(:all, :conditions => "ploeg =
''SR'' OR ploeg ''''")
end
def self.pupil
Player.find(:all, :conditions =>{:ploeg =>"P"})
end
def self.junior
Player.find(:all, :conditions =>{:ploeg =>"J"})
end
def self.topm
@man = Player.find_all_by_geslacht("M", :order => "score
DESC",
:limit => 3)
end
def self.topv
@vrouw = Player.find_all_by_geslacht("V", :order => "score
DESC",
:limit => 3)
end
protected
def validate
# errors.add(:fieldname_as_symbol, "foutboodschap")
end
end
[/code]
thanks for your help
Paul
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---