Skip to content

Comments

Add conditional updates_for helper#202

Merged
leastbad merged 1 commit intomasterfrom
conditional-updates-for
May 9, 2022
Merged

Add conditional updates_for helper#202
leastbad merged 1 commit intomasterfrom
conditional-updates-for

Conversation

@julianrubisch
Copy link
Contributor

In the app I'm currently developing, it has occurred that I want to conditionally wrap a block of ERB in updates_for based on authorization. So typically one would do:

<% if policy(post).edit? %>
  <%= updates_for post ... %>
    <%= post.content %>
  <% end %>
<% else %>
  <%= post.content %>
<% end %>

which, depending on your setup, might lead to a lot of duplication. This PR simplifies it to

<%= updates_for_if policy(post).edit?, post ... %>
  <%= post.content %>
<% end %>

in the spirit of link_to_if etc.

@julianrubisch julianrubisch requested a review from leastbad May 7, 2022 06:42
@julianrubisch julianrubisch added enhancement proposal ruby Pull requests that update Ruby code labels May 7, 2022
@leastbad leastbad merged commit aab58aa into master May 9, 2022
@leastbad leastbad deleted the conditional-updates-for branch May 9, 2022 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement proposal ruby Pull requests that update Ruby code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants