helpers

AssetTagHelper::image_path outside views

ε祈祈猫儿з 提交于 2019-12-08 17:35:56
问题 Supposedly, ActionController::Base.helpers acts like a proxy for accessing helpers outside views. However many of the methods defined there rely on controller variables and I'm unable to succesfully call: ActionController::Base.helpers.image_path("my_image.png") >> TypeError Exception: can't convert nil into String Digging at the source I see compute_asset_host method is trying to access config.asset_host but config is nil . How can I successfully call image_path from outside views? 回答1: Use

dynamic rails helpers (eg. link_to method, method)

时光怂恿深爱的人放手 提交于 2019-12-07 11:56:56
问题 I was wondering how to get some dynamic abilities for my rails helpers: <h3><%= link_to object.name, ("#{object.class_path.to_s}")_path(object) %></h3> In this case, throwing it the object's class into a link to. I'm getting confused on how to throw a method within a helper method. Any advice would be greatly appreciated! 回答1: You're trying to link to the instance of the object? <%= link_to object.name, object %> Rails can construct a #show link from that. You can use polymorphic_path for

How to access a helper from the controller in CakePHP?

风格不统一 提交于 2019-12-07 08:17:34
问题 Well, this is a tricky one, and I'm not really sure it's not breaking the MVC model. I'm loading some data into the controller, retrieved from the model. I'm passing this object to the view almost in every action. I'm processing this data from a helper and I'm passing the object as an argument: controller: $this->('section', $section); helper: <h3><?php echo $parser->section_name($section); ?></h3> However, I think it would be way better if I could pass that $section object as a private

Symfonian way to store custom utilities and helpers in symfony 2

旧巷老猫 提交于 2019-12-07 03:55:03
问题 Sometimes there are some functions or procedures that I write as helpers and utilities to use all across my apps... Now I'm starting to use Symfony 2, and I don't know what is the best way according to symfony 2 philosophy of Bundles... I wouldn't like to have to create a whole Bundle just to store maybe a couple of functions, but if it is the best way I'll do it. Thanks! 回答1: If your utilities and helpers are not Symfony specific, create a library in a separate repo and install it to vendors

How can I generate a unique dom id for a html tag from model

▼魔方 西西 提交于 2019-12-07 02:38:17
问题 I am having an index view with several rows for items which have multiple attributes. I would like to update the content of an items attribute with ajax, therefore I need a unique dom id. Is there a helper method available? What I am doing right now is: <span id="<%= item.id.to_s + "_on_storage"%>"> Best, Phil 回答1: You can use dom_id(item) Which is an ActiveRecord method for generating DOM IDs. 回答2: A good practice as well is to use HTML5 data attributes: <span data-item-id="<%= item.id %>">

Mac app store helper tool Sandboxing

空扰寡人 提交于 2019-12-06 10:26:40
问题 My app consist of two executables the main app executable small console app to process some files, this executable is on Resources folder (no root privileges required) The thing is that I don't know how to submit this app to appstore, I get the following response from apple Invalid Signature - the main app bundle appname at path appname.app is signed but the signature is invalid. The following error(s) were reported from codesign: a sealed resource is missing or invalid In architecture: i386

dynamic rails helpers (eg. link_to method, method)

假装没事ソ 提交于 2019-12-06 02:15:33
I was wondering how to get some dynamic abilities for my rails helpers: <h3><%= link_to object.name, ("#{object.class_path.to_s}")_path(object) %></h3> In this case, throwing it the object's class into a link to. I'm getting confused on how to throw a method within a helper method. Any advice would be greatly appreciated! You're trying to link to the instance of the object? <%= link_to object.name, object %> Rails can construct a #show link from that. You can use polymorphic_path for more complicated/nested situations: <%= link_to object.name, polymorphic_path([:edit, @user, object]) %> ...as

Rails 3 strip whitespace before_validation on all forms

為{幸葍}努か 提交于 2019-12-06 00:31:30
问题 I'm relatively new to Rails and a bit surprised this isn't a configurable behavior...at least not one I've been able to find yet?!? I would have thought that 99% of forms would benefit from whitespace being trimmed from all string & text fields?!? Guess I'm wrong... Regardless, I'm looking for a DRY way to strip all whitespace from form fields (of type :string & :text) in a Rails 3 app. The Views have Helpers that are automatically referenced (included?) and available to each view...but

How to access a helper from the controller in CakePHP?

南楼画角 提交于 2019-12-05 15:59:59
Well, this is a tricky one, and I'm not really sure it's not breaking the MVC model. I'm loading some data into the controller, retrieved from the model. I'm passing this object to the view almost in every action. I'm processing this data from a helper and I'm passing the object as an argument: controller: $this->('section', $section); helper: <h3><?php echo $parser->section_name($section); ?></h3> However, I think it would be way better if I could pass that $section object as a private variable inside the parser helper. I could do this in the first line of each view: $parser->section_object =

Symfonian way to store custom utilities and helpers in symfony 2

丶灬走出姿态 提交于 2019-12-05 07:48:25
Sometimes there are some functions or procedures that I write as helpers and utilities to use all across my apps... Now I'm starting to use Symfony 2, and I don't know what is the best way according to symfony 2 philosophy of Bundles... I wouldn't like to have to create a whole Bundle just to store maybe a couple of functions, but if it is the best way I'll do it. Thanks! Elnur Abdurrakhimov If your utilities and helpers are not Symfony specific, create a library in a separate repo and install it to vendors using the deps with the bin/vendors install command or via Composer , which will become