Rails object inheritance with belongs_to -


I have a simple relation between the report and the chart, I have a problem that is causing the problem Is that my chart model is a parent whose children are

Then in my report model I have

  class Report & lt; ActiveRecord :: Base is - Medium: Chart End  

And my chart model is a parent, where all the succession from the pie, line, bar chart are I do not know where it is located: the report is in the chart model or is under the children of the chart model. I get errors when I try to use the chart. Report because the object is of "class" type

Report class for undefined local variable or method # #: 0x104974b90>

Chart model uses STI Which says its pulls .. 'Ling' from the chart_ type column in the chart table .. What am I missing?

Edit

  chart / \ pie line / \ / gender gender  
< P> I am transforming an object immediately, type gender, or sex hopes that it helps a bit more.

I feel that the reason for this

  @ chart.update_attributes (params [: chart])  

Because when its real [: Charts] Paramat [: Ling] or Param [: Sex]

Your problem is that you have a controller that receives all these different types of models. When you use Rail form assistants, they are taking the object type from the example and using it to populate the parameter, it means that you have parameter [: gender] Instead of params [: chart]

You can correct by overriding the method that uses the rail form, place the following code in your base chart category: < / P>

  def self.model_name name = "chart" name.instance_eval def def Uvcn; Pluralize; End DEF singular; Singularize;  

Now, a child of the chart will be passed in the form of params [: chart]

in your received action

maybe trust some plugins / gems. You should check to make several controllers. Instead of having chart controller to get all the data, there is a GenderChartsController and a LineChartsController . It offers two benefits:

  1. You do not need to change the object name
  2. If you need a custom code for a particular type of chart in the future, To add conditional statements, it has to work, because different controllers have separated it for you.

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -