view-helpers

Unpermitted parameters in rails 4

喜夏-厌秋 提交于 2019-11-30 11:33:40
I read about collection_check_boxes but I don't understand how can I set the checked values. I have the following model: class Objective < ActiveRecord::Base has_many :indicators has_many :objective_children, class_name: "Objective", foreign_key: "parent_id" def objective_ids objective_children.collect{|o| o.id} end def objective_ids= objectives_ids objectives_ids.each do |id| objective_children << Objective.find(id) end end end edit view: <%= form_for(@objective) do |f| %> <%= f.collection_check_boxes :objective_ids, Objective.all, :id, :name %> <%= f.submit %> <% end %> the html checkbox are

Removing parameters from URL when using Url view helper links

。_饼干妹妹 提交于 2019-11-30 07:35:12
When using the Url view helper to build links, if the current page has parameters in the url, the url generated by the Url view helper will contains parameters as well. For instance in the page /controller/action/param/value/ the following code: <a href="<?php echo $this->url(array( 'controller' => 'index', 'action' => 'index' )) ?>">Dashboard</a> will output: <a href="/index/index/param/value/">Dashboard</a> Is it possible to clean the url outputted by the helper of parameters? David Snabel-Caunt I think the third parameter to the helper will clear the default params, e.g. <a href="<?php echo

Unpermitted parameters in rails 4

谁都会走 提交于 2019-11-29 17:17:35
问题 I read about collection_check_boxes but I don't understand how can I set the checked values. I have the following model: class Objective < ActiveRecord::Base has_many :indicators has_many :objective_children, class_name: "Objective", foreign_key: "parent_id" def objective_ids objective_children.collect{|o| o.id} end def objective_ids= objectives_ids objectives_ids.each do |id| objective_children << Objective.find(id) end end end edit view: <%= form_for(@objective) do |f| %> <%= f.collection

Removing parameters from URL when using Url view helper links

僤鯓⒐⒋嵵緔 提交于 2019-11-29 09:35:33
问题 When using the Url view helper to build links, if the current page has parameters in the url, the url generated by the Url view helper will contains parameters as well. For instance in the page /controller/action/param/value/ the following code: <a href="<?php echo $this->url(array( 'controller' => 'index', 'action' => 'index' )) ?>">Dashboard</a> will output: <a href="/index/index/param/value/">Dashboard</a> Is it possible to clean the url outputted by the helper of parameters? 回答1: I think

What is the best practice to create a custom helper function in php Laravel 5?

家住魔仙堡 提交于 2019-11-28 20:32:06
I have the default created_at date keep printing out as an MySQL format : 2015-06-12 09:01:26. I wanted to print it as my own way like 12/2/2017 , and other formats in the future. I created a file called DataHelper.php and store it at /app/Helpers/DateHelper.php - and it looks like this <?php namespace App\Helpers; class DateHelper { public static function dateFormat1($date) { if ($date) { $dt = new DateTime($date); return $dt->format("m/d/y"); // 10/27/2014 } } } I want to be able to called it in my blade view like DateHelper::dateFormat1($user->created_at) I'm not sure what to do next. What

Rails 3 View helper method in Model

早过忘川 提交于 2019-11-28 09:21:52
I have a class method in my model, and I need to access a method from one of my view helpers. Currently I am including include TalkHelper , but I still get a NoMethodError. You may place helper in your lib folder and include them anythere. Like this: lib/some_helper.rb module SomeHelper def somedef #your code there end end Innerpeacer In your model, you can do something like the following: ApplicationController.helpers.your_helper_method OR YourController.helpers.your_helper_method The best solution is to refactor your code so that you don't need to call view helper code at all from models. It

zf2 Creation of simple service and access it through viewhelper

烂漫一生 提交于 2019-11-28 06:03:16
I am trying to create a simple service in zf2 which I can access using in viewhelper Step1. I have craeted a class in src/Application/Service/Service1.php as follow namespace Application\Service; use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorInterface; class Service1 implements ServiceLocatorAwareInterface { public function __construct() { } public function setServiceLocator(ServiceLocatorInterface $serviceLocator) { } public function getServiceLocator() { } } Step2 I set this up in module.php file as below. public function getServiceConfig() {

Rails 3.1: Better way to expose an engine's helper within the client app

做~自己de王妃 提交于 2019-11-27 19:22:42
I have found a few articles addressing the issue of helpers within an engine not being accessible to the consuming (parent) application. To make sure we are all on the same page, let's say we have this: module MyEngine module ImportantHelper def some_important_helper ...do something important... end end end If you look at the rails engine documentation in the "Isolated engine's helpers" (L293), it says: # Sometimes you may want to isolate engine, but use helpers that are defined for it. # If you want to share just a few specific helpers you can add them to application's # helpers in

Where to put Ruby helper methods for Rails controllers?

流过昼夜 提交于 2019-11-27 18:55:01
I have some Ruby methods certain (or all) controllers need. I tried putting them in /app/helpers/application_helper.rb . I've used that for methods to be used in views. But controllers don't see those methods. Is there another place I should put them or do I need to access those helper methods differently? Using latest stable Rails. You should define the method inside ApplicationController . John Cleary For Rails 4 onwards, concerns are the way to go. There is a decent article here http://richonrails.com/articles/rails-4-code-concerns-in-active-record-models In essence, if you look in your

How to add a view helper directory (zend framework)

我怕爱的太早我们不能终老 提交于 2019-11-27 15:00:31
I begin with ZF (1.9.7), and I want to use View Helpers from a library shared between all my projects. But I can't find how to add it directory to the helpers path. My herpers works fines when I put them in application's helpers path. Here is the error, where I find the path to ZF helpers, and path to the applications ones. object(ArrayObject)#71 (3) { ["exception"]=> object(Zend_Loader_PluginLoader_Exception)#70 (6) { ["message:protected"]=> string(151) "Plugin by name 'Voo' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/;C:/ZendStd/www/applis/VOO4_PROJECTX