0

私のビューには次のコード行があります。

<%= link_to(@a.heroes[i]['name'], edit_d3user_d3hero_path(@temp_d3user, @temp_d3hero)) %><br/>

次のエラーが表示されますが、その理由がわかりません

No route matches {:action=>"edit", :controller=>"d3heros", :d3user_id=>#<D3user id: 4, x_battleTag: "rwk-1242", x_timePLayed: nil, x_killMnstrTtl: 1014469, x_killsEliteTtl: 51552, x_lastHeroPlayed: "10692899", x_game_id: nil, created_at: "2013-01-14 13:10:35", updated_at: "2013-01-14 23:10:17">, :id=>false}

コードを手動で変更する

<%= link_to(@a.heroes[i]['name'], edit_d3user_d3hero_path(@temp_d3user, 1)) %><br/>

動作するため、問題は @temp_d3hero オブジェクトの ID がコードによってプルされていないことに切り分けられます。

@temp_d3hero のデバッグ

--- !ruby/object:D3hero
attributes:
  id: 1
  x_name: Ziyi
  x_class: wizard
  x_id: '10692899'
  x_level: 60
  ...

@temp_d3user のデバッグ

--- !ruby/object:D3user
attributes:
  id: 4
  x_battleTag: rwk-1242
  x_timePLayed: !!null 
  x_killMnstrTtl: 1014469

そして最後に私のモデル

D3ヒーロー

class D3hero < ActiveRecord::Base
  attr_accessible :x_class, :x_name, :x_level, :x_life, :x_damage, :x_id , :x_gender

  validates :x_id, presence: true, uniqueness: true

  belongs_to :d3user
end

D3ユーザー

class D3user < ActiveRecord::Base
  attr_accessible :x_battleTag, :x_game_id, :x_killMnstrTtl, :x_killsEliteTtl, :x_lastHeroPlayed, :x_timePLayed

  has_many :d3heros
end

そしてroutes.rb

D3gearcheck::Application.routes.draw do
  get "d3heros/new"

  get "d3users/new"

  resources :users
  resources :sessions, only: [:new, :create, :destroy]
  resources :heroines
  resources :d3users do
    resources :d3heros
  end
  resources :d3heros

それを機能させる方法についての助けは大歓迎です。

ありがとう!

UPDATE-コントローラー

def resultv2
@mystring = params[:battleTag]
@mystring.gsub!("#", "-")  

@a = Covetous::Profile::Career.new @mystring
# after is interpret only if no exception before
flash.now[:success] = 'Battle Tag Lookup Successful'
@acount = @a.heroes.count

#### hack -- d3user not created. create it now. Otherwise, update now.

@d3user = D3user.find_by_x_battleTag(@mystring)
if !@d3user
  D3user.create(:x_battleTag => @mystring,
                :x_killMnstrTtl => @a.kills['monsters'],
                :x_killsEliteTtl => @a.kills['elites'],
                :x_lastHeroPlayed => @a.lastHeroPlayed) 
else
  @d3user.update_attributes(:x_battleTag => @mystring,
                           :x_killMnstrTtl => @a.kills['monsters'],
                           :x_killsEliteTtl => @a.kills['elites'],
                           :x_lastHeroPlayed => @a.lastHeroPlayed)     
end

また、@temp_d3hero と @temp_d3user は、

<% @temp_d3user = local_d3user?(params[:battleTag]) %>
<% @temp_d3hero = local_d3hero?(@a.heroes[i]['id']) %>

上記の2つのオブジェクトのデバッグで示されているように、有効で正しいオブジェクトも返しています

4

1 に答える 1

0

これを試して

<%= link_to(@a.heroes[i]['name'], edit_d3user_d3hero_path(@temp_d3user, @temp_d3hero.id)) %><br/>
于 2013-01-15T05:22:43.050 に答える