Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

render_cell_for ArgumentError #106

Closed
kris opened this Issue · 7 comments

3 participants

@kris

Hi,

Using Ruby 1.9.2, Rails 3.1.3, and Cells via GitHub source.

Error:

ArgumentError (wrong number of arguments (0 for 1)): config/routes.rb:8:in `block (2 levels) in '

Code:

 post 'newsletter/signup' => Proc.new { |env|
    [200, {}, [Cell::Base.render_cell_for(:newsletter, :signup)]]
  } 

Based on closed tickets, this appeared to be an existing bug that was solved, but not on my end. Any input?

Thanks

@apotonick
Owner

A detailed stacktrace would help!!!

@mckenziec

Same problem here. This is a big issue for anyone using render_cell_for in routes. Any progress? Thanks!

@apotonick
Owner

You're trying to render a subclass of Cell::Rails which requires an ActionController instance! Derive your NewsletterCell from Cell::Base, that should work. But be warned that not everything might work since a lot of Rails helpers are tied to the controller instance. You could also keep your NewsletterCell as a Cell:Rails subclass and pass a controller instance:

Cell::Base.render_cell_for(:newsletter, :signup, controller_instance)

but then it's up to you creating the controller. Does that help/make sense for you?

@mckenziec

Not to hijack anything, maybe my case will help.

My Cells are Cell::Rails derived, so I can get access to :session, etc... not Cell::Base.

class ActivityCell < Cell::Rails

If Cell::Rails inherits Cell::Base, and Base would normally have everything it needs to render_cell_for a Cell::Base, why would rendering a Cell::Rails not work? Is there a more appropriate way to render a Cell::Rails from a route?

match "/widget/:name" => proc { |env|
  cell_name = env["action_dispatch.request.path_parameters"][:name]
  [ 200, {}, [ Cell::Base.render_cell_for(cell_name, :display) ]]
}
@apotonick
Owner

Hm, what exactly do you need in your cell, @mckenziec? Access to sessoin, and whatelse? And, do you really need it, or could you pass it as arguments into the cell?

@mckenziec

That's a good idea actually. I guess the session could be passed to the render_cell_for from the route code. The rack.session exists in env. But the only reason I need the session is for Devise anyways. (I'm using some Devise methods, which the session is needed for)

match "/widget/:name" => proc { |env|
  cell_name = env["action_dispatch.request.path_parameters"][:name]
  [ 200, {}, [ Cell::Base.render_cell_for(cell_name, :display) ]]
}

So is this the right way to do this, or just a suggestion/work around? What about working with Devise and CanCan from within a Cell that's called from a route? (al'la AJAX JSON request) Again, not trying to hi-hack. Just adding content to a question about render_cell_for. Thanks!

@apotonick apotonick closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.