Strange behavior of show in applic

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

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

this is the edit.rhtml

<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' %>

de show rhtml

<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' %>

de _form.rhtml


<%= 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]-->

the model is this


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

thanks for your help

Paul

it’s a bit late and i’m not sure, i analyzed your code to it’s full
extend, but this function

def ploeg
@@ploegen = :ploeg
end

looks a bit weird to me, because:

  • you assign a symbol to a class attribute
  • and hand this back

so the effect is like:
def ploeg
“ploeg”
end

  • and it’s within all those class level funcs the only object lvl
  • and it overwrites the ploeg accessor

Thorsten,
you did point out the right place however changing it here did not solve
a thing I tried @ploeg instead of :ploeg and ‘ploeg’
but no change here do you have a sugestion to replace this?

thanks
paul

Thorsten M. wrote:> it’s a bit late and i’m not sure, i analyzed
your code to it’s full > extend, but this function> > def ploeg>Â
@@ploegen = :ploeg> end> > looks a bit weird to me, because:> - you
assign a symbol to a class attribute> - and hand this back> > so the
effect is like:> def ploeg>Â Â “ploeg”> end> > - and it’s within all
those class level funcs the only object lvl> - and it overwrites the
ploeg accessor

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs