1

Right now I have some grave problems concerning the functionality of my linear optimization app which should be a breeze for programmers like you.

First of all, my seed.rb does not seed the data as desired. I have a simple table with 4 coloumns and 1 row. However, when I try to seed, ruby automatically generates two db entries instead of one. Moreover, it puts the values not in one row but places them diagonally in various rows.

So instead of getting a row like 1|1|1, I get:

1|-|-|
-|1|-|
-|-|1|

and instead of creating 4 entries, it creates 8. Same goes for creating one entry which generates 2.

Here's my seed.rb:

Period.create([{ period_nr: '1'}])

Capacity1.create([{ capacity_labour: '0'}, {capacity_machines: '0'}, {max_additional_personal_capacity: '0'}, {price_per_additional_capacity: '0'}])

Another issue I have is with automatically transferring values in a table. I have a table where I want that when you edit the value in one coloumn, all the other values in this very coloumn change accordingly.

example:

|0|0|0|
|0|0|0|

turns to:

|0|0|2|
|0|0|2|

when I enter 2 in the third coloumn first row, it should automatically get transferred to the third coloumn second row. Is there an easy way?

Please help me, this is for an essay which is due in just about a week. I m really desperate!

1 Answer 1

1

you can proceed as follow in your seed.rb file:

p=Period.new(:period_nr => 0)
c=Capacity.new(:capacity_labour => 0, :capacity_machines => 0, :max_additional_personal_capacity => 0, :max_additional_personal_capacity =>0 )
p.save
c.save

I'm not sure I understood the rest. can you be clearer?

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for your help, really! However, I'll try to explain my problem concerning the tables once more: I want to enter a value in a coloum and it should automatically get transferred to all the other values in that coloumn. Imagine you have a table with a coloumn called periods. Now I have a value which does not change over the course of those periods but its still in my table. Usually one would be required to enter this value manually in every row, I want that one only has to enter it once, anywhere in the coloumn.
you can use a loop to do do
Where do I have to code that loop? My Table looks as follows: <thead> <tr> <th>Period</th> <th>Demand</th> <th>Production coefficient machines</th> </tr> </thead> <tbody> <% @product_as.each do |product_a| %> <tr> <td><%= best_in_place product_a, :period %></td> <td><%= best_in_place product_a, :demand %></td> <td><%= best_in_place product_a, :production_coefficient_machines %></td> </tr> <% end %> </tbody> </table> And I want the production_coefficient to automatically be transferred.
Since it uses the .each method, the table wants a different production_coefficient for all periods...
You could use update_all to make sure it is changed everywhere. Or you might want to think about creating a new model that holds that value so you just have to change the value of the relation and not every entry
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.