Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unset an instance variable? #28

Open
CharlieHawker opened this issue Apr 29, 2016 · 5 comments
Open

Unset an instance variable? #28

CharlieHawker opened this issue Apr 29, 2016 · 5 comments

Comments

@CharlieHawker
Copy link

We are using render_anywhere to render a series of pages, and as such there is a loop.

There are some instances where instance variables are set on iterations of the loop that won't be needed on the next iteration. Leaving them assigned causes rendering issues, but there is no unset_instance_variable method (or similar).

Re-initializing the object which uses the render_anywhere gem on each iteration of the loop would evidently solve this but would be an expensive operation.

Would adding a method like the following be a viable solution?

def unset_instance_variable(var) 
  rendering_controller.class_eval do
    undef :"#{var}"
    undef :"#{var}="
  end
end
@robb1e
Copy link
Contributor

robb1e commented Apr 30, 2016

Happy to look at at pull request if you have time.

Robbie

On Fri, 29 Apr 2016, 17:22 Charlie Hawker, [email protected] wrote:

We are using render_anywhere to render a series of pages, and as such
there is a loop.

There are some instances where instance variables are set on iterations of
the loop that won't be needed on the next iteration. Leaving them assigned
causes rendering issues, but there is no unset_instance_variable method
(or similar).

Re-initializing the object which uses the render_anywhere gem on each
iteration of the loop would evidently solve this but would be an expensive
operation.

Would adding a method like the following be a viable solution?

def unset_instance_variable(var)
rendering_controller.class_eval do
undef :"#{var}"
undef :"#{var}="
endend


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#28

@CharlieHawker
Copy link
Author

Great. Working on one now after discussing best solution on stack overflow.

@CharlieHawker
Copy link
Author

@robb1e am I missing something about testing? Both rake and rspec (even when prefixed with bundle exec) don't seem to be able to render the views in spec/views and the tests produce the following error:

RenderAnywhere#render renders with ivar
     Failure/Error: rendering_controller.render_to_string(*args)
     ActionView::MissingTemplate:
       Missing template spec/views/user_ivar with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:erb, :builder]}. Searched in:

Given Search in: is blank, is that a misconfiguration / version issue?

@robb1e
Copy link
Contributor

robb1e commented May 8, 2016

Hmm, I just pulled the latest and run the tests successfully. Not sure what to suggest, I haven't been involved in this code base for a while.

@CharlieHawker
Copy link
Author

Yep, it's driving me crazy too! Any particular version of Ruby / Rspec? Thanks for taking a look.

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

No branches or pull requests

2 participants