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

Invoking render in a view method ? #121

Open
ljulliar opened this issue Aug 8, 2022 · 6 comments
Open

Invoking render in a view method ? #121

ljulliar opened this issue Aug 8, 2022 · 6 comments

Comments

@ljulliar
Copy link

ljulliar commented Aug 8, 2022

Hi everyone,

First time testing Camping. So far I like it very much. I was just wandering if it's possible to invoke render from within a view method ? The reason I'm asking is because when I do so it seems that the instance variables initialized in the controller action doesn't seem to pass through the embedded render call. Am I missing something here ?

Thank you for your help.

@karloscarweber
Copy link
Member

This is interesting. Perhaps provide some sample code and I can diagnose the issue.

@ljulliar
Copy link
Author

Sure. Here is code sample below. Notes:

  1. if I removed the locals argument it doesn't change a thing
  2. There is no error/exception of any kind. It's just that the _ats_table partial is not rendered
  3. rendar :ats (the main view) is called from an Ospweb controller as usual
  4. if I call self._ats_table instead of calling render :_ats_table it works well
module Ospweb::Views
  def ats
    h3 "Archetypes"
    render :_ats_table, locals: { ats_stats: @ats_stats }
  end

  def _ats_table
   # some HTML rendering here using @ats_stats
  end
end

@karloscarweber
Copy link
Member

karloscarweber commented Aug 16, 2022

Try this:

module Ospweb::Views
  def ats
    h3 "Archetypes"
    _ats_table({ :ats_stats => @ats_stats })
  end

  def _ats_table(locals)
   # some HTML rendering here using @ats_stats
   p "Paragraph tag using some stats: #{locals[:ats_stats]}"
  end
end

In Markaby / Mab helper methods are immediately output when called. So you can use view helpers with mab as partials.

Slight reference: http://markaby.github.io

The mab documentation definitely needs to be improved. I'll put it on my list.

@ljulliar
Copy link
Author

Thank you for your suggestion. It is actually a variant of calling of self._ats_table and passing locals. I'll try that. Thanks

@karloscarweber
Copy link
Member

@ljulliar let me know how it went.

@ljulliar
Copy link
Author

ljulliar commented Aug 25, 2022 via email

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