首页 \ 问答 \ ActiveModel序列化未生效(ActiveModel Serialization not taking effect)

ActiveModel序列化未生效(ActiveModel Serialization not taking effect)

我正在尝试渲染特定属性但所有属性的返回方式,似乎AMS没有任何效果。

串行:

class ImagesSerializer < ActiveModel::Serializer
  attributes :id, :facility_id, :title, :description
end

I'm trying to render how the specific attributes but all attributes are getting returned, it seems like AMS isn't having any effect.

Serializer:

class ImagesSerializer < ActiveModel::Serializer
  attributes :id, :facility_id, :title, :description
end

原文:https://stackoverflow.com/questions/32571215
更新时间:2023-02-22 19:02

最满意答案

^

你可以使用它并用#替换。参见demo。

https://regex101.com/r/eX9gK2/5

$re = "/^/m"; 
$str = "string "; 
$subst = "#"; 

$result = preg_replace($re, $subst, $str);

^

You can use this and replace by #.See demo.

https://regex101.com/r/eX9gK2/5

$re = "/^/m"; 
$str = "string "; 
$subst = "#"; 

$result = preg_replace($re, $subst, $str);

相关问答

更多
  • ^ 你可以使用它并用#替换。参见demo。 https://regex101.com/r/eX9gK2/5 $re = "/^/m"; $str = "string "; $subst = "#"; $result = preg_replace($re, $subst, $str); ^ You can use this and replace by #.See demo. https://regex101.com/r/eX9gK2/5 $re = "/^/m"; $str = "strin ...
  • 也许你的字符串是UTF-8? PHP。 你必须做这样的事情: $ability1 = utf8_decode($ability); $ability1 = preg_replace("/[£ ]/","", $ability1); $ability1 = utf8_encode($ability1); Maybe your string is in UTF-8? PHP. You would have to do something like this: $ability1 = utf8_decode($ ...
  • 你不仅可以修剪空白,并使用urlencode()将内部空间转换为+ ? 如果你有其他字符不能被URL编码,这是行不通的。 但我们不知道你的全部要求。 urlencode(trim($string)); $string = " bah bah"; echo urlencode(trim($string)); // bah+bah Can you not just trim whitespace and use urlencode() to convert the interi ...
  • 只需使用stripslashes功能 http://php.net/manual/en/function.stripslashes.php I don't know if this is considered a good practice but what I did was: $output = nl2br(str_replace('\\r\\n', "\r\n", $string)); echo str_replace('\\', "", $output);
  • 不是。诚实地说,如果你没有准备好你的陈述,你是在寻求一个受到伤害的世界。 仅仅因为你用引号来避开你的引用,你并不能保护你自己。 想想这个: 用户发送给您: username'; drop database foo; username'; drop database foo; 你会将它作为username''; drop database foo;转义username''; drop database foo; username''; drop database foo; 但! 如果用户确实: usernam ...
  • 不要那样做,使用number_format() ,它会为你处理它。 Don't do it that way, use number_format(), which'll handle it all for you.
  • 事实证明。 您的字符串使用html-entities编码。 所以你只需查看源代码或使用highlight_string($yourString)就能看到这一点,然后你会看到: < 而不是< 。 要解码它,只需使用html_entity_decode() 。 例如: $string = str_replace("
    ","", html_entity_decode($string)); highlight_string($string); So as it turns out. Your s ...
  • 这是我建议的一个例子。 演示: http : //codepad.viper-7.com/bSODv7
  • $ValHas仍然是PHP中的字符串 ,其值为"" 。 它没有#s。 在客户端的Javascript评估函数之前,它不会变成'#123-12555 ' 。 如果要删除哈希客户端,请执行以下操作: var hasvalue = window.location.hash.replace('#', ''); $ValHas is still a string in PHP, with a value of "