Sounds to me like we could call this a bug.
> 2) there should be a feature that allows widget rendering by class
> from a view and does not bypass assignments from controller
I think
render :widget => TestWidget
is what you're after.
It works from inside a controller, and should work inside a template
view (e.g. erb) too. Though maybe it doesn't work either :-)
see https://github.com/pivotal/erector/blob/master/spec/rails_root/spec/render_spec.rb
> now if I want to fall back to assignment with a controller instance
method unless it is assigned locally or in controller, I need to do
this
How about...
class Views::Students::StudentSideBar < Erector::Widget
needs :student => nil
def student
@student || helpers.current_user
end
def content
text student.name
end
end
Yes, you'd have to wait until the controller is set before calling the
controller (helpers).
I like the idea of adding procs to the "needs" system, but I'm not
sure why you'd pass in "helpers" (the controller) to it... maybe you'd
pass in the widget itself...
On Mon, Jul 25, 2011 at 8:21 AM, Viktor Trón <vikto...@gmail.com> wrote:
> however incorrect or unexpected if done with the widget method.
>
> The widget instance method is defined in abstract_widget and non-rails
> specific, bypasses the controller assignmentsSounds to me like we could call this a bug.
> 2) there should be a feature that allows widget rendering by class
> from a view and does not bypass assignments from controllerI think
render :widget => TestWidget
is what you're after.It works from inside a controller, and should work inside a template
view (e.g. erb) too. Though maybe it doesn't work either :-)see https://github.com/pivotal/erector/blob/master/spec/rails_root/spec/render_spec.rb
> now if I want to fall back to assignment with a controller instance
method unless it is assigned locally or in controller, I need to do
thisHow about...
class Views::Students::StudentSideBar < Erector::Widget
needs :student => nildef student
@student || helpers.current_user
enddef content
text student.name
end
endYes, you'd have to wait until the controller is set before calling the
controller (helpers).I like the idea of adding procs to the "needs" system, but I'm not
sure why you'd pass in "helpers" (the controller) to it... maybe you'd
pass in the widget itself...
sure, if you prefer. in fact the block could just be instance evaled in widget scopeby the initializer.