Ruby on Rails problem
Hej,
Det är så att jag tagit över driften av en site med enormt komplicerad ruby kod (för mig i varje fall).
I grunden är det en guildsida för min wowguild, med egenskapat DKP system av en företagsekonom (och förra hosten av sidan).
Det hela är uppbyggt av pgSQL och Ruby. SQL biten klarar jag av, men Ruby är rena grekiskan för mig.
Basically, vi har fasta priser på saker, normal pris och offspec pris. Förut har bara ett pris sparats i databasen, men jag har fixat en kolumn för att lägga till offspec priset också. Nu hade jag tänkt fixa en fin liten checkbox för att välja vilket pris man vill sälja ett föremål för.
i app/views/raids/edit.haml så har jag lagt till det vid --->:
- form_tag(:controller => "raids", :action => :create_loot, :raid_id => @raid.id) do
%table
%tr
%td= collection_select("loot", "character_id", @characters, "id", "name", { :include_blank => true })
%td= collection_select("loot", "item_id", @items, "id", "name", { :include_blank => true })
%td= collection_select("loot", "mob_id", @raid.zone.mobs, "id", "name", { :include_blank => true })
%td= text_field("loot", "price", { :size => 8 })
---> %td= check_box("loot", "secondary", { :include_blank => true }, "yes", "no")
%td= submit_tag("Add loot")
i app/model/loot.rb :
class Loot < ActiveRecord::Base
belongs_to :mob
belongs_to :item
belongs_to :character
belongs_to :raid
validates_presence_of :character_id
validates_presence_of :item_id
validates_presence_of :raid_id
validates_numericality_of :price
---> validates_presence_of :secondary
def initialize(attributes = nil)
---> if (attributes[:secondary].eql? "yes")
---> attributes[:price] = Item.find(attributes[:item_id]).secondary_price
elseif (attributes[:price].length <= 0)
attributes[:price] = Item.find(attributes[:item_id]).default_price
end
super(attributes)
end
def self.total_value
total = self.sum(:price, :include => :character, :conditions => [ "characters.active = ?", true ])
if total.nil?
total = 0.0
end
return total
end
end
och i db/schema.rb:
create_table "items", :force => true do |t|
t.string "name"
t.integer "wowid", :null => false
t.float "default_price", :default => 0.0, :null => false
t.float "secondary_price", :default => 0.0, :null => false
end
Jag har försökt få detta att funka i några veckor nu, men utan ens den minsta Ruby kunskap så har detta nästan fått mig att avsky all form av programmering... Ruby säger ju inte ens var det är fel, den bara säger fel. Om någon kan hjälpa vore jag otroligt tacksam, och om det behövs kan jag fixa SSH access till servern.
Light travels faster than sound. Is that why some people appear to be smart before they speak?
It's a big rock. I can't wait to tell my friends. They don't have a rock this big.