Created
April 4, 2015 11:59
-
-
Save ysinc88/dbf164084846f49385b5 to your computer and use it in GitHub Desktop.
each loop from 2 models
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
class PagesController < ApplicationController | |
def store | |
@products = Product.all | |
end | |
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
class CreateProducts < ActiveRecord::Migration | |
def change | |
create_table :products do |t| | |
t.integer :product_category_id | |
t.string :name | |
t.text :description | |
t.decimal :price | |
t.string :currency | |
t.string :image | |
t.timestamps null: false | |
end | |
end | |
end | |
class CreateLedConfigurations < ActiveRecord::Migration | |
def change | |
create_table :led_configurations do |t| | |
t.integer :product_id | |
t.integer :led_id | |
t.integer :series_sum | |
t.integer :series_led_count | |
t.string :name | |
t.integer :wl | |
t.integer :quantity | |
t.timestamps null: false | |
end | |
end | |
end | |
class CreateLeds < ActiveRecord::Migration | |
def change | |
create_table :leds do |t| | |
t.string :name | |
t.integer :wl | |
t.decimal :fv | |
t.decimal :A | |
t.decimal :price | |
t.timestamps null: false | |
end | |
end | |
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
class Product < ActiveRecord::Base | |
has_one :led_configuration | |
has_many :leds, through: :led_configuration | |
end | |
class LedConfiguration < ActiveRecord::Base | |
belongs_to :product | |
belongs_to :led | |
end | |
class Led < ActiveRecord::Base | |
has_many :led_configurations | |
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
<% @products.each do |p| %> | |
. | |
. | |
. | |
<% p.leds.each do |l| %> | |
<tr> | |
<td><%= l.wl %></td> | |
<td><%= l.price.to_s + "$" %></td> | |
<td><%= p.led_configuration.series_led_count %></td> # Here is the problem | |
<td><%= p.led_configuration.series_sum %></td> # Here is the problem | |
</tr> | |
<% end %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment