trailblazer / cells

View components for Ruby and Rails.
https://trailblazer.to/2.1/docs/cells.html
3.07k stars 236 forks source link

Render cell outside controller #283

Closed toomus closed 9 years ago

toomus commented 9 years ago

How to render cell outside controller and view?

eg.

   class ChatCell < Cell::Rails
      def single_message(data)
         @message = data[:message]
         render
       end
   end
   # I need something like this
   class MyCustomClass
      msg = render_cell(:chat, :single_message, { message: @some_msg_obj })
   end

Of course render_cell is undefined. How to do this?

apotonick commented 9 years ago

Cell::Rails.render_cell_for(nil, :chat, :single_message, message: ..)

http://www.rubydoc.info/gems/cells/3.6.0/Cell/ClassMethods:render_cell_for

toomus commented 9 years ago

Thx, but now I have something like that:

NoMethodError (undefined method `builders' for Cell:Module):

setup

Ruby 2.2.0
rails 4.2.0  
rspec 3.2.0
cells 3.11.3
rspec-cells 0.2.2
apotonick commented 9 years ago

Sorry I gave you the wrong information - I probably wasn't drunk enough.

::Cell::Rails.render_cell_for(name, state, controller, *args, &block)

That's the correct one. Why ain't you not using Cells 4?

toomus commented 9 years ago

After update Cells to 4.0.0.beta2, when I try to start server:

.rvm/gems/ruby-2.2.0/gems/rspec-cells-0.2.2/lib/rspec/cells/cell_example_group.rb:7:in 
`<module:CellExampleGroup>': uninitialized constant Cell::TestCase::TestMethods (NameError)
apotonick commented 9 years ago

Eeeh.. you know that Cells 4 is not Cells 3? Rspec + Unit support for Cells 4 coming!

toomus commented 9 years ago

So what I have to do to run server? Uninstall rspec-cells?

apotonick commented 9 years ago

Pretty much, yeah, but there's some API changes, too, and structural changes, and so on. I think I blogged about it, but I recommend the 4 line anyway.

We're on #trailblazer on Freenode IRC, in case you need support!

seuros commented 9 years ago

or use rspec-cells from master