2012-01-08 13 views
15

best_in_place gemでネストされたリソースを使用することが可能かどうか(もしそうなら、どのような構文であるか)を知っていますか?Rails best_in_placeネストされたリソースを持つ宝石

私のroutes.rbを、私は目標の:descriptionフィールドを編集したいと思い、この

resources :users do 
    resources :goals 
end 

のようなものに見えますが、

<%= best_in_place [@user, @goal], :description %> 

ための私の見解でコードが

を言っNoMethodErrorを与えます
undefined method `description' for #<Array:0x20e0d28> 

使用方法

<%= best_in_place @goal, :description %> 

goal_path

が、私は問題なく@userのために働く宝石(非ネストされたリソース)フィールドを取得することができますが存在しないためにも、私に未定義のメソッドエラーを与えます。私はRailsの3.1.1、Rubyの1.9.2を実行している

は、1.0.4

答えて

19

best_in_place私はそれを考え出しました。

私はそれが今チャンピオンのように動作しますので、

<%= best_in_place @goal, :description, :path => user_goal_path %> 

のようなコールでpathオプションを設定するために必要な!

+0

私は同様の問題を抱えています。http://stackoverflow.com/questions/30090219/best-in-place-building-exotic-method-after-creation – Sauron

1

ありがとう、@bknoles。あなたの答えは間違いなく私自身の同様の解決に達するのを助けました。ここに私の実装があります:

#widget.rb 
class Widget < ActiveRecord::Base 
    validates_presence_of :name 
    has_many :gadgets 
    attr_accessible :name, :description 
end 

#gadget.rb 
class Gadget < ActiveRecord::Base 
    belongs_to :widget 
    attr_accessible :name, :widget_id, :id 
end 


#gadgets_controller.rb 
    def update 
    @[email protected](params[:id]) 
    if @gadget.update_attributes(params[:gadget]) 
     respond_to do |format| 
     format.html 
     format.json { respond_with_bip(@gadget) } 
     end 
    else 
    respond_to do |format| 
     format.html { render :action => "edit" } 
     format.json { respond_with_bip(@gadget) } 
    end 
    end 
    end 


#views/gadgets/_gadget.html.haml 
%tr{ :name => "gadget_", :id => gadget.id } 
    %td= gadget.created_at.localtime.strftime("%B %d, %l:%M%p") 
    %td.big=best_in_place gadget, :name, :path => [@widget, gadget] 
    %td.delete{:style => 'text-align:center;'} 
    =check_box_tag "gadget_ids[]", gadget.id, false, :class => "checkbox" 

もっと多くのコードを見たい場合は、githubでプロジェクト全体をチェックアウトすることができます。

https://github.com/hernamesbarbara/ajax-rails-full-crud

ベスト、 オースティン

10

はパスへのパスとオブジェクトを追加します。

<%= best_in_place @goal, :description, :path => user_goal_path(@user,@goal) %> 

どういうわけかbknolesの簡単なパス・ソリューションは私のために動作しませんでした。

+0

他にも驚異的な出来事があります。ありがとう。 – Galaxy

4

上記のメソッドは廃止予定です。最新のドキュメントの使用によると

":URL":

<%= best_in_place @goal, :description, :url => user_goal_path %> 

乾杯の例では、以下のような "パス" の代わりに!

関連する問題