get filter Ghost blog related posts by tag - ghost

I'm trying to get a list of related posts by tag using the Get helper in Ghost blog.
I tried to follow the cookbook in Ghost docs to get the related posts by tag, but it seems some of the syntax has changed slightly (I know it's a beta feature!).
But I got it working with this on my post.hbs (this is within the {{#post}} block):
{{#get "posts" limit="4" include="tags" filter="tags.name:[Test]+posts.id:-{{id}}" as |related|}}
{{!-- do appropriate stuff --}}
{{/get}}
The obvious problem is the Test tag is hardcoded here. Even though {{tags}} outputs a list of tags for me, it doesn't work here:
App 22174 stderr: ERROR: Query Error: unexpected character in filter at char 11
App 22174 stderr: tags.name:[[object Object]]+pos
App 22174 stderr: -----------^
App 22174 stderr: Expecting 'NULL', 'TRUE', 'FALSE', 'NUMBER', 'LITERAL', 'STRING', got 'LBRACKET'
App 22174 stderr: Error parsing filter
App 22174 stderr: For more information on how to use filter, see http://api.ghost.org/docs/filter
Anyone have any ideas?
PS This is using version 0.11.7 (I just saw that 0.11.8 was recently released, but the changelog doesn't note anything related from what I can see).

I've also been having a problem with using the filter to get related posts by tags and I've finally solved it. So just in case you haven't, or for anyone else that may come across this...
I was having problems with parsing of the filter. This is my code now using the get helper that is working for me (note: my sidebar is within my {{#post}} block):
{{#get "posts" limit="3" filter="tags:[{{tags[*].slug}}]+id:-{{id}}" include="tags"}}
{{#foreach posts}}
<p>{{title}}</p>
{{/foreach}}
{{/get}}
One of my problems seemed to be the fact that some of my tags are 2 words, which meant I had to reference the slug of the tag (which is what tags[*].slug is doing).
I also had one tag that had a single letter (Ghost automatically made the C# tag slug just c) and the filter doesn't like that either. I edited the slug to be c-sharp and now it's all working.

Related

Repeated "859: unexpected token" exceptions in a Rails 6 application

Over the last several weeks, my Rails 6.1 app has been raising hundreds of exceptions like the following:
An ActionDispatch::Http::Parameters::ParseError occurred in regdevs#create:
859: unexpected token at
'utf8=%E2%9C%93&authenticity_token=fnrg63qtelQvkQx9NQx8SaZIp7mR500toEiWdaJe91
%2FOzsEvRbGD4Ow6NNADCtjw7H3EkDvFZVGP4gQkGZceEw%3D%3D&user%5Bemail%5D=jrmills91
%40hotmail.com&user%5Bfirst_name%5D=wJAhzNnPWbqMdfH&user%5Blast_name%5D=tKdp
IVXJlneZbiuA&user%5Bnickname%5D=lBdbyYgiaHt&user%5Bpassword%5D=0SgLpVuf5Wqs
%21&user%5Bpassword_confirmation%5D=0SgLpVuf5Wqs%21&user%5Bterms_of_service
%5D=1&commit=Complete+registration&g-recaptcha-response=dzghTWcBpmI'
The error occurs when "someone" tries to register for a new account (via Devise) with bogus credentials. It clearly looks like some sort of attack.
I have two questions:
How can I find out more about this specific 859 unexpected token error?
Should I be concerned? The recaptcha guard seems effective in blocking account creation, but I wonder if I am missing something
I partially decoded the response by hand mostly just to see what it looked like.
utf8=%E2%9C%93
authenticity_token=fnrg63qtelQvkQx9NQx8SaZIp7mR500toEiWdaJe91/OzsEvRbGD4Ow6NNADCtjw7H3EkDvFZVGP4gQkGZceEw==
user[email]=jrmills91#hotmail.com
user[first_name]=wJAhzNnPWbqMdfH
user[last_name]=tKdpIVXJlneZbiuA
user[nickname]=lBdbyYgiaHt
user[password]=0SgLpVuf5Wqs!
user[password_confirmation]=0SgLpVuf5Wqs!
user[terms_of_service]=1
commit=Complete+registration
g-recaptcha-response=dzghTWcBpmI
The first line is utf8= and then that is the unicode for checkmark. Perhaps that is part of the captcha?
The user names etc clearly look bogus. I bet jrmills is getting lots of weird email. :-)
The ParseError is defined in parameters.rb and you can see the call that created it inside parse_formatted_parameters. The only place that calls it is from request.rb.
From the comments in the code (and what I would expect), if the authenticity_token doesn't match, an ActionController::InvalidAuthenticityToken should be raised. So, the parse error (I'm guessing) is lower down but I can't spot why the JSON or Ruby code would be complaining. I think I would have written that piece of code differently: captured the error and included the original error message with the new error -- but... such is life.
I would attempt to track down the IP address where these are being sent from and block that IP address if possible or at least see if it is the same address or if they form a pattern.
Depending upon what you are protecting would alter my level of concern. It seems plausible that a validation on the first and last name could be written that would reject this particular style of name. i.e. capital letters in the middle of the name? You could also flag any email going to "bogus" places like hotmail, yahoo, gmail, etc and require them to go through a moderator before being approved.
It also seems plausible to rig up a test case using this response to recreate the issue. Then add debug code to the Rails code until the precise reason for the exception is better understood.

Customizing All errors symfony 1.4

Sorry for my English and writing through a translator.
I'm new here and I'm a bit lost in what I want, maybe you can help me out if they wish, as explained here:
I want to customize all the errors that may be produced (any status code that is a mistake. 404, 500, 204, 301 .... etc.) And also show suggestions based on the "module" and/or "action" from where the error occurred.
I also wish I could tell by the file redirection "setting.yml" application, something like this:
error_404_module: common
error_404_action: errors
error_500_module: common
error_500_action: errors
error_204_module: common
error_204_action: errors
error_301_module: common
error_301_action: errors
........
Within the "app/frontend/modules/common" in the "action.class.php" define "executeErrors" in which I receive the status code that has occurred and the module where the error occurred or except for well, getting partial show "app/frontend/modules/common/templates/_errorXXXSuccess.php" and the partial of the suggestion that I seek and extract the module "referer" where the error occurred.
Well, that's the idea, dynamic content for different types of error in different circumstances and working perfectly with the type codes 404 but not with the rest ...
I read that could place me in the middle of the event by creating a file "config/error.html.php" and "config/exception.html.php". Indeed if I produce such a 500 error and manually these files are executed. The problem is that from there I can not access variables from symfony. Because if so I could invoke "common/errors" and bad send as parameters the error status code and the module where it occurred, but it is not. From there all I can do is play with $ _SERVER and routing.yml but can not get good results because the environment is mixed with Development Production (/frontend_dev.php) and is something I also want to avoid.
That is, I want to get as in "setting.yml" does "error_404_module" and "error_404_action" but with different error codes. Thus allowing me to show my custom pages in production based on "error or exception" and/or "module or action" where the error has been released from production, and in case of being in development mode (/frontend_dev.php/....), show the symfony Dispatch.
Surely life is complicandome and has a simpler way to do what I want but after thousands of combinations do not get the right result. Even if symfony may not allow other types of error redirect from "setting.yml" is because they are reserved for him or something. I do not understand.
Please please help me because no documentation to find and secure here at least we left public for others who want to do something.
Many Thanks and greetings!
First of all - you can't get symfony to intercept all errors. Some of the errors may be server errors and the request won't even get to your application. You can reproduce some of them explicitly setting responses in symfony though, but I may not be necessary to deal with all of them.
As for the exact response: you should use a listener to hook your errors to a class that handles them according to your need. See: https://stackoverflow.com/a/7077818/580167 for implementation details.

sfGuardPlugin 4.0.2 breaks with sfPropelORMPlugin

A recent pull request requires 'isCrossRef: true' for the many to many list widgets to be generated in forms. Pull Request: https://github.com/propelorm/sfPropelORMPlugin/pull/90
The default forms will throw a fatal error when they try to set the labels for these list that aren't there anymore in the base classes.
Posting this up on SO in case someone else runs into this problem, because it took me a while to figure out.
this is fixed since a week, see: https://github.com/propelorm/sfPropelORMPlugin/pull/136

Omit attribute name from validation error message (at start of it)?

I write code in English but I'm currently doing a site which is fully translated to another language (validation error messages included). However, I have a problem because validation error messages always seem to include the name of the attribute the error is on at the start of the error, e.g.:
Title Prosimo izpolnite naziv fakultete.
I want to get rid of the Title at the start, like so:
Prosimo izpolnite naziv fakultete.
Any help is appreciated. I would rather see if this can be solved without installing any 3rd party plugins.
If it's possible to provide translations for attribute names, that would be a cool solution too, but I would still like to know how it can be done both ways (omit or translate).
There is no need to use the error_messages_for helper for errors, you can write your own helper using the record's errors attribute.
You can just iterate over the error objects and display their messages.

Netbeans/Ruby - extraneous(?) autocomplete info

I'm getting a ton of (what I would call) extraneous autocomplete information in Ruby Netbeans 6.5.1.
For example, if I type the name of a model object and then type a period (whether I'm in a controller or a view), it shows a dizzying dropdown list of thousands of methods, including several hundred different versions of the "new" method (but no documentation - most method signatures are followed by "No comment found").
Has anyone encountered (and solved) this problem, if we agree that this is a problem? Could it be that I simply have access to all of those thousands of methods and so they must be reported by autocomplete?
I have exactly the same behavior.
I'm guessing because variables in Ruby are dynamically typed, Netbeans is being a little enthusiastic. Coming from a Java background it is a bit surprising.
It does appear to put the columns in my table at the top of my ActiveRecord objects ... so that's nice!

Resources