Skip to content
This repository has been archived by the owner on Oct 19, 2018. It is now read-only.

Possible Naming Conflict Between Model and Component #3

Open
hermiti opened this issue Sep 2, 2016 · 2 comments
Open

Possible Naming Conflict Between Model and Component #3

hermiti opened this issue Sep 2, 2016 · 2 comments

Comments

@hermiti
Copy link

hermiti commented Sep 2, 2016

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
Copy link

Aaron2Ti commented Nov 7, 2017

does

        @schedules = ::Schedule.all

work for you?

@catmando
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants