Rails best_in_place嵌套资源gem
有谁知道是否有可能(如果是这样,语法是什么)与best_in_place gem一起使用嵌套资源?Rails best_in_place嵌套资源gem
我的routes.rb看起来像这样
resources :users do
resources :goals
end
我想编辑的目标:description
领域,但在我看来,代码
<%= 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,1.9.2红宝石,best_in_place 1.0.4
我想通了。
我需要的path
选项调用像这样
<%= best_in_place @goal, :description, :path => user_goal_path %>
它的工作原理就像现在一个冠军设定!
谢谢@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
最佳, 奥斯汀
添加路径和对象的路径:
<%= best_in_place @goal, :description, :path => user_goal_path(@user,@goal) %>
不知何故bknoles的简单路径解决方案并没有为我工作。
也创造了奇迹。谢了哥们。 – Galaxy 2013-12-08 00:13:26
现在上面的方法已被弃用。
根据最新的文档使用“:网址”,而不是“:路径”如下面的例子
<%= best_in_place @goal, :description, :url => user_goal_path %>
干杯!
你可以协助,我有一个类似的问题:http://stackoverflow.com/questions/30090219/best-in-place-building-exotic-method-after-creation – Sauron 2015-05-07 01:53:05