We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
It should be a render like any other. Do you render or redirect after that line? Show the controller action if you like and I'll try to help.
No, I was trying to use it with 4.1 ActionPack Variants and running into a whole sleuth of errors.
I'd be happy to try it out in a 4.1 app if you show a minimal example of code that breaks.
Here's one that can also take an action: https://gist.github.com/hen...
Good article! I am leaning towards using locals vs. instance variables when my app starts growing. Primarily because it plays well with hexagonal approach but being explicit in more complex scenarios is good.
You said "If you need to check for the presence of a key, defined?(item) will not work but local_assigns.has_key?(:item) will." which version of rails was that tested on?
I tested it on rails 4.2 and using defined? in the view seem to work, have a look:
Thank you! Two years after writing this post, I still use locals in new projects.
I don't remember what version I tried it on – I suppose it may have been Rails 3. Good to know `defined?` works on 4.2.
It indeed seems to have been fixed sometime around 4.2: http://nithinbekal.com/post...
what about the specs! Rspec lets you assert on `assigns` but not on passed locals hash. :/
I very rarely write controller specs – perhaps there is something like `local_assigns` or `view.local_assigns` you could use. If not, they would probably accept a pull request for it.
I've been developing with Rails for the third year now and this approach is growing increasingly appealing. Being explicit about what variables a template or partial relies on saves a lot of headache. It also moves one towards passing views a single hash of data to work with fewer locals and this bodes well with eventually passing the data as JSON to a frontend framework like Angular or React.
For me this caused a DoubleRenderError when used in conjunction with a respond_to block. Am I overlooking something?