helpers

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

你离开我真会死。 提交于 2019-12-05 07:22:50
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 You can use dom_id(item) Which is an ActiveRecord method for generating DOM IDs. A good practice as well is to use HTML5 data attributes: <span data-item-id="<%= item.id %>"> 来源: https://stackoverflow.com/questions/11817398/how-can-i-generate-a-unique-dom-id-for-a-html-tag-from-model

WooCommerce - get_order() is not working

▼魔方 西西 提交于 2019-12-05 06:38:39
I'm trying to create a function that will retrieve an order by its ID. For some reason I can't get the WooCommerce global function get_order to work. I'm passing a valid order id to the function and trying to print it out to verify that it's working. The function has been placed in my functions.php file. function getWC_order_details($id){ global $woocommerce; $order = get_order( $id ); print "<pre>"; print_r($order); print "</pre>"; } I have tested echoing other data out of the function without a problem. First of all make function like this : function getWC_order_details($order_id) { $order =

Body class for controller in Rails app

耗尽温柔 提交于 2019-12-05 01:50:01
问题 Currently I have this in my layout: <body class="<%= controller.controller_name %>"> I want to add an additional class that will be the same for all actions in any controller where it's set, something like: class SomeController < ApplicationController body_class 'page' ... end class AnotherController < ApplicationController body_class 'page' ... end Which will result in: <body class="some page"> <body class="another page"> What would be the easiest way to achieve this? Can I use controller

Rendering templates within helpers in handlebars

混江龙づ霸主 提交于 2019-12-04 19:34:40
问题 Hey guys! Because there seem to be no answer on this: Passing variables through handlebars partial yet, I'm currently working on a little workaround to get this work. So, the idea is to register a helper function which renders a specific template with possible values. A bit code makes it better to understand. This is how a I'd invoke my helper: <div> {{myHelper}} </div> This helper is registered with this little code: hbs.registerHelper(name, function (args) { args = args || {}; var template

Mac app store helper tool Sandboxing

让人想犯罪 __ 提交于 2019-12-04 15:13:00
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 If I remove helper app, it bypasses this error, but app won't work at all. Anyone knows a good way or

Change default Rails text_area helper rows/cols

六眼飞鱼酱① 提交于 2019-12-04 10:55:32
I am finding myself specifying :rows => 5 on all my text_area form helpers, So I looked up its definition and found the DEFAULT_TEXT_AREA_OPTIONS to be the hash dictating these options. However, the hash has this freeze method on it and I looked it up, it means it can't be changed. If you could recommend me some options to try to do a app-wide :rows => 5 for all text area, I'd really appreciate it. Thanks You can do: Write own helper: def readable_text_area(form, method, options = {}) form.text_area(method, options) end or redefine text_area method delegating to original text_area with proper

How can I modify the input type of the Rails datetime_select helper?

戏子无情 提交于 2019-12-04 09:48:00
问题 I am using the Rails helper datetime_select in one of my forms. I currently have a requirement to change the dropdowns for day , year , hour , and minute to be textboxes with validation. Is there a way I can specify that I want textboxes for these fields? Or possibly a different helper that will do what I need? here is my usage: datetime_select(:campaign, :start_date, :order => [:day, :month, :year, :hour, :minute]) 回答1: how about rolling your own simple helper, like def datetime_text_fields

Are there any view helpers to generate CSS?

人盡茶涼 提交于 2019-12-04 09:02:17
I like the idea of HTML helpers, which allows me not to write all the HTML for common elements, while still gives me full control, preserves model-view separation and can be strongly typed. I'm wondering if it is possible to generate CSS stylesheets or style definitions the same way - using helpers in view markup? Ideally, I would like to have some of the CSS generated based on some object-oriented rules and definitions. I can't find any solutions that will offer anything more than stylesheet compression and merging. What you're asking for isn't impossible, but the way things are configured by

Rails 3 strip whitespace before_validation on all forms

别说谁变了你拦得住时间么 提交于 2019-12-04 06:29:19
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 Models don't seem to have such a thing?!? Or do they? So currently I doing the following which first

Using link_to in a class in a Rails helper

时光怂恿深爱的人放手 提交于 2019-12-04 03:07:18
I have a rails helper using the structore below, but when I use it I get the message undefined method 'link_to' The helper is arranged as: module MyHelper class Facet def render_for_search link_to("Value", params) end end class FacetList attr_accessor :facets def initialize #Create facets end def render_for_search result = "" facets.each do |facet| result << facet.render_for_search end result end end end This is because within the Class Facet you don't have access to the template binding. In order to call the render_for_search method you probably do something like <%= Facet.new.render_for