1

in rails I would have a controller for widgets with an index, show, and crud methods.
the index controller would have a simple

@widgets = Widget.all
respond_to do |format|
  format.html
  format.json {render :json => @widgets}

then, on my home page, or any page in my main apps folder, I could say

<% @widgets.each do |w| %>
     <p><%= w.name %></p>
<%end%>

With Refinery I have a widgets engine, and the controllers in those engines don't have the standard index, show, and crud methods. If I override the home action in refinery pages_controller.rb with the code above I get the error

uninitialized constant Refinery::PagesController::Widget

My question is: how do I refer to classes in my refinery engines such that I can include them in my views from my main rails app?

Example: app.main.views.index.html.erb

 <h1> this is my home page.  We sell all sorts of stuff including: </h1>

 <% @widgets.each do |w| %>
      <p><%= w.name %></p>
 <%end%>

 <% @gadgets.each do |g| %>
     <p><%= g.name %></p>
 <%end%>

where both widgets and gadgets are refinery engines. I have a vanilla rails app that does this very thing and it works but I would like to know how to do it in refinery, because figuring this out will open the world to me. Could someone please advise or point to some documentation I might have overlooked that will help out.

EDIT This is the home action in my pages_controller.rb located in app>controllers>refinery directory:

 def home
  @widgets = Widget.all
  respond_to do |format|
    format.html
    format.json { render json: @widgets}
  end  
  #render_with_templates?
 end
rakitin
  • 1,943
  • 6
  • 25
  • 51
  • 1
    Have you tried overriding the default refinery controllers and add custom routes – TheIrishGuy Mar 29 '13 at 03:37
  • I am overriding the default pages_controller.rb located in the app>controllers>refinery directory. The only change I made is in the home action. – rakitin Mar 29 '13 at 13:58

1 Answers1

0

Refinery CMS names its engine namespaces with the plural model name. It then nests the engine namespaces within a Refinery namespace. So the correct way to query for all my widgets in a view within the main app structure is

@widgets = Refinery::Widgets::Widget.all
rakitin
  • 1,943
  • 6
  • 25
  • 51