Creating filters for auto_html - ruby-on-rails-3

I want to create a custom filter for auto_html. Where do I put the filter so I can use it?
The documentation doesn't touch on any of that. Thanks!

The approach I took was to add the code to an initializer file such as:
/path/to/your/application/config/initializers/auto_html.rb
Then you can just write something like:
AutoHtml.add_filter(:change_colours).with({}) do |text, options|
text.gsub("#FF0000", "#00FF00")
end
And call auto_html(input) { change_colours } in your model. The empty hash will take any options you care to pass to the filter.

Related

Inputs for searching (form:select)

Is it possible to use Search like this in order to refer a specific {name} provided by an input? I want to create an input form like: <form:select items="${cars}" path="car" itemLabel="type" itemValue="id"/>. This is my controller mapping: #GetMapping("/searchby/{name}"). Thanks!
it should be possible but not recommended, from what i know using url parameters (domain.com/page?value=theValue) is better

How can we make an Item in socialengine?

I know how to get an item of the particular table. Like for user we can have
$userItem = Engine_Api::_()->getItem("user", $userId);
or for a custom table
$customItem = Engine_Api::_()->getItem("custom", $customeId);
I want to know the code or method how can I make my $customItem to work the same way as $userItem works for users table. So that I can get data or manipulate the data of custom table
Thanks for your help. :-)
You can achieve that by creating a model. Check how it's done in /application/modules/User/Model. There is User.php file that declares User_Model_User and methods available for User such as getTitle, get Href etc.
You may use similar approach for your custom item. You will also need to create a file similar to /application/modules/User/Model/DbTable/User.php to declare table for your custom items.

Where to write common function or logic in laravel 4.2

I want to use a common function or logic in all controllers on laravel4.2, what would be best way to do this? Does Anyone have any idea?
You can use Helper for that.
Create helpers.php in app folder.
You can create normal function there which you can use anywhere in laravel.
Example syntax for function :
function YOUR_FUNCTON_NAME(param1,param2) {
#YOUR_CODE
}
After creating helpers.php file , add it in app/start/global.php file.
like below :
require app_path().'/helpers.php';
And you can use anywhere in your controller like this YOUR_FUNCTON_NAME(param1,param2)
Hope this help.

using sylius_resource_sort with indexByTaxon action

I'm trying to add sorting to my Product:indexByTaxon action using sylius_resource_sort
I set "sortable" to true for resources. It seems though that this action doesn't support sorting at any point yet.
What would be the best apporach here? Should I replace it with modified Product:indexAction and add taxon as a criteria?
That twig extension does not work with relationship, first you need to sort on a virtual property :
{{ sylius_resource_sort('my_taxon_property') }}
After that, you need to override your repository define your own method and play with sorting. You can have a look to the method findBy()?

How do I get only the query string in a Rails route?

I am using a route like this
match "/v1/:method" => "v1#index"
My intention here is capture the name of the api method and then send the request to that method inside the controller.
def index
self.send params[:method], params
end
I figured this would send the other parameters as an argument to the method, but it didn't work. So my question is how can I pass the non-method parameters in a query string?
#query_parameters does exactly what you want:
request.query_parameters
It's also the most efficient solution since it doesn't construct a new hash, like the other ones do.
Stolen from the work of a colleague. I find this a slightly more robust solution, since it will work even if there are changes to the path parameters:
params.except(*request.path_parameters.keys)
I sort of solved this problem by doing this:
params.except("method","action","controller")