ruby-hyperloop / reactive-record

The project has moved to Hyperstack!!
https://hyperstack.org/
MIT License
14 stars 2 forks source link

Possible Naming Conflict Between Model and Component #3

Open hermiti opened 8 years ago

hermiti commented 8 years ago

While creating a component using

rails g reactrb:component Schedule::Index

If a model exist that matches "Schedule" is used within the component. It will not work:

module Components
  module Schedule
    class Index < React::Component::Base

      before_mount do
        @schedules = Schedule.all
      end

      def render
        ul do
          @schedules.each do |schedule|
            li { schedule.title }
          end
        end
      end

    end
  end
end

What happens is that the Schedule.all tries to use the Component method instead of the reactiverecord model.

index:260 Exception raised while rendering #<Components::Schedule::Index:0x2f6>

    at Opal.defs.TMP_1 [as $new] (<eval>:24540:15)
    at module_constructor.ːmethod_missing (<eval>:23097:54)
    at module_constructor.method_missing_stub [as $all] (<eval>:20693:35)
    at $Index.$a.$$p.TMP_1 (<eval>:85402:56)
    at $Index.ːinstance_exec (<eval>:23026:24)
    at ːrun_callback.$b.$$p.TMP_2 (<eval>:61709:88)
    at Opal.yield1 (<eval>:20885:14)
    at Array.ːeach (<eval>:30895:26)
    at $Index.ːrun_callback (<eval>:61712:64)
    at ːcomponent_will_mount.$a.$$p.TMP_8 (<eval>:63038:23)

I think that documentation may be sufficient to resolve this issue in the future or perhaps an error thrown during generating the original component if a model already exists with the same name.

Aaron2Ti commented 6 years ago

does

        @schedules = ::Schedule.all

work for you?

catmando commented 6 years ago

yes we by convention name Components things like JobIndex, or ShowJob but never the name of the AR model.