fast_jsonapi icon indicating copy to clipboard operation
fast_jsonapi copied to clipboard

Have conditional link ? similar to conditional attributes.

Open ritesh2741 opened this issue 6 years ago • 3 comments

getting TypeError ({:if=>#Proc:0x00007fb68de748e8} is not a symbol nor a string) when trying to use , link :sms_url, if: proc { | params| params[:action] == 'sms' }

and I am sending the params through options = {params: {action: 'sms'}}

ritesh2741 avatar Nov 09 '18 06:11 ritesh2741

We do not have conditional links yet. Is this a feature request or a bug report?

manojmj92 avatar Nov 09 '18 06:11 manojmj92

@manojmj92 More of a feature request or if there is a workaround

ritesh2741 avatar Nov 09 '18 18:11 ritesh2741

The only work around I found was to just pass a conditional statement in the block that returns null.

Consider the following:

  link :approve do |record, params|
    approve_comment_path(record) if params && params[:admin]
  end

  link :deny do |record, params|
    deny_comment_path(record) if params && params[:admin]
  end

Would return:

{
    data: [
        {
               ...snippet
              links: [
                   approve: null,
                   deny: null
              ]
        }
   ]
}

I agree that conditional links would be a nice feature.

pyrabbit avatar Dec 26 '18 15:12 pyrabbit