Created
March 14, 2012 03:51
-
-
Save kurenn/2033919 to your computer and use it in GitHub Desktop.
Problema con nested resources y un render parcial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="control-group"> | |
<div class="controls"> | |
<%= link_to_add_fields("Agregar producto", f, :requisitions) %> | |
<%= f.fields_for :requisitions do |builder| %> | |
<%= render :partial => 'requisition_fields', :locals => {:f => builder } %> | |
<% end %> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="fields"> | |
<%= builder.label :product_id, "Nombre del producto", :class => "product_label" %> | |
<%= builder.text_field :product_id, :class => "product-token", "data-product" => data_product_one(@products.pop) %> | |
<%= builder.label :color_id, "Color" %> | |
<%= builder.text_field :color_id, :class => "color-token", "data-color" => data_product_one(@colors.pop) %> | |
<%= link_to_remove_fields "Sacar de la orden", builder %> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def data_product_one(product) | |
attributes = {} | |
array = [] | |
attributes[:id] = product.id | |
attributes[:name] = product.name | |
array << attributes | |
array.to_json | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".product-token").each -> | |
product = $(this).data("product") | |
$(this).tokenInput("/products.json", { | |
crossDomain: false, | |
prePopulate: product, | |
hintText: "Escribe un producto", | |
noResultsText: "No se encontraron resultados", | |
searchingText: "Buscando...", | |
tokenLimit: 1 | |
}) |
Si dejame lo agrego...
No entiendo muy bien :( ... pero te puedo dar varias observaciones, que talvez puedan hacer que resuelvas el problema:
Pienso que sería bueno que quitaras las variables de instancia del parcial y las pasaras, desde el llamado a "render()" ....
Me imagino que el partial de requisitions_fields, se escribe una vez para cada requisición, entonces sería bueno que pasaras "collection: @requisitions" y en el parcial tendrias acceso a esa requicisión y podrías hacer "requisition.product" .... Lo que no entiendo es que parece que @requisitions no es una colección de requisiciones, sino una cantidad.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tienes el metodo data_order_one ?