سؤال

I'm trying to create an admin partial that has all the utility addons I need for my website in one file to reduce clutter, using a local I should be able to tell what part I need based of the string that I pass as a local.

= render 'admin/projects', locals: { utility: "delete" }

and in my _projects

- if request.subdomain == 'admin'
  -if :utility == "delete"
    %button.delete

When run no button appears, if set to != 'delete' a button appears.

Why isn't my variable being set?

هل كانت مفيدة؟

المحلول

You're comparing a string to a symbol, you probably want to write:

- if request.subdomain == 'admin'
  -if utility == "delete"
    %button.delete

Your render syntax is also a bit off, instead of:

= render 'admin/projects', locals: { utility: "delete" }

Use

= render :partial => 'admin/projects', locals: { utility: "delete" }

I answered a similar question earlier here: Rails asking for a secret key to create model

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top