2014-03-05 21 views
1
get '/watch/:id' do |id| 
    @results = Twitchtvst.all(:fields => [:Twitchtv ], 
       :conditions => { :user_id => "#{id}" }   
       ) 
    #p @results.inspect 
    @results.each do |result| 
     puts result.id 
    end 

    erb :mystream 
    end 

我得到這個錯誤消息immutable資源不能被延遲加載。我該如何解決?Ruby DataMapper :: ImmutableError

錯誤消息是:

DataMapper::ImmutableError at /watch/1 
Immutable resource cannot be lazy loaded 
+2

什麼錯誤信息??? – Severin

+0

不可變的資源不能被延遲加載 – user2945872

回答

1

根據官方documentation

需要注意的是,如果你不包括在選定列主鍵,你會不會能夠修改返回的資源,因爲DataMapper無法知道如何保存它們。如果您嘗試這樣做,DataMapper將會拋出DataMapper :: ImmutableError。

我知道你在這裏沒有修改任何東西,但我認爲同樣的規則適用於延遲加載。所以我會建議嘗試這樣的:

@results = Twitchtvst.all(:fields => [:Twitchtv, :id], 
      :conditions => { :user_id => "#{id}" }   
      ) ode here 

請注意id作爲附加字段。

相關問題