helpers

CakePHP select default value in SELECT input

旧时模样 提交于 2019-11-29 11:34:11
问题 Using CakePHP: I have a many-to-one relationship, let's pretend it's many Leafs to Trees. Of course, I baked a form to add a Leaf to a Tree, and you can specify which Tree it is with a drop-down box ( tag) created by the form helper. The only thing is, the SELECT box always defaults to Tree #1, but I would like it to default to the Tree it's being added to: For example, calling example.com/leaf/add/5 would bring up the interface to add a new Leaf to Tree #5. The dropdown box for Leaf.tree_id

System.Web.Helpers not found in VS2015

天涯浪子 提交于 2019-11-29 09:17:10
I'm trying to add some JSON parsing to the C# code in VS2015 but I can't find: System.Web.Helpers as the MS documentation suggests. I've looked at other people's questions of a similar nature (almost all on earlier versions) and the answers all say to add it in the Assemblies / Framework dialog. The problem is it doesn't appear in that dialog, nor do many of the other things I see people talking about. I would really appreciate any help on fixing this. Here is the list I have access to: Edit: Added the Extensions window as well This question is a bit old but here's a simple solution -

Rails 3. How to add a helper that ActiveAdmin will use?

五迷三道 提交于 2019-11-29 02:01:26
问题 I'm creating a helper to be used by Formtastic but I get the undefined local variable or method error. I don't know where to put it so it can work. I already tried in the application_helper.rb and in app/helpers/active_admin/view_helpers.rb 回答1: You can define them in app/helpers/ as you tried but you need to include them trough the active admin's initializer like this: # in config/initializers/active_admin.rb ActiveAdmin.setup do |config| .... end module ActiveAdmin::ViewHelpers include

Calling helper method from Rails 3 controller

不问归期 提交于 2019-11-28 22:40:03
Is it possible to call helper methods from controller? If yes how to do this in Rails 3? view_context.some_helper_method You can either include the helper module in the controller, or define the helper as a controller method and mark it as a helper via helper_method :method_name . class FooHelper def bar ... end end class QuxsController include FooHelper end or class QuxsController private def bar ... end helper_method :bar end This is working if some one wants to use ApplicationHelper method in other controllers or view just add this include ApplicationHelper give below because all your

SessionsHelper in railstutorial.org: Should helpers be general-purpose modules for code not needed in views?

旧巷老猫 提交于 2019-11-28 21:19:03
railstutorial.org has a suggestion which strikes me as a little odd. It suggests this code : class ApplicationController < ActionController::Base protect_from_forgery include SessionsHelper end The include SessionsHelper makes the methods available from ApplicationController , yes, but it makes them available in any view, as well. I understand that authentication/authorization is cross-cutting, but is this really the best place? That seems to me to be potentially too broad of a scope. Putting code which implements, say, a before_filter which conditionally redirects (as the railstutorial.org

“undefined method” when calling helper method from controller in Rails

做~自己de王妃 提交于 2019-11-28 16:40:01
Does anyone know why I get undefined method `my_method' for #<MyController:0x1043a7410> when I call my_method("string") from within my ApplicationController subclass? My controller looks like class MyController < ApplicationController def show @value = my_method(params[:string]) end end and my helper module ApplicationHelper def my_method(string) return string end end and finally, ApplicationController class ApplicationController < ActionController::Base after_filter :set_content_type helper :all helper_method :current_user_session, :current_user filter_parameter_logging :password protect_from

Change protocol to https in all rails helpers

断了今生、忘了曾经 提交于 2019-11-28 11:00:02
Rails 3.1+ I want my url helpers to use the https protocol without having to specify it in every helper I call. After searching around I've found various ways but none work, for example: ROUTES_PROTOCOL = (ENV["RAILS_ENV"] =~ /development/ ? 'http://' : 'https://') scope :protocol => ROUTES_PROTOCOL, :path => "/app" do How can this be done? So you want it mainly for links in emails? I think this will work in your production.rb, development.rb or any other environment. config.action_mailer.default_url_options = { :host => 'yourwebsite.com', :protocol => 'https' } # Makes it possible to use

Override rails helpers with access to original

独自空忆成欢 提交于 2019-11-28 09:00:48
I want to use rails' familiar helpers, but with slightly altered functionality. The way I see it, I want to be able to do something like: module AwesomeHelper #... create alias of stylesheet_link_tag to old_stylesheet_link_tag def stylesheet_link_tag(*args) if @be_awesome awesome_stylesheet_link_tag *args else old_stylesheet_link_tag *args end end end The way I see it, I have three options: Monkey patching: Reopening the rails helper module. If the rails team ever change the name of their helper module, my code becomes a source of brittleness. Not insurmountable, but not ideal. Use different

Custom form helpers

亡梦爱人 提交于 2019-11-28 04:33:00
Is there a way that I can create a custom form helper so that instead of: special_field_tag :object, :method I can achieve something like: form.special_field :method Yes, you can add to the FormBuilder class and get access to the object passed into the form_for. I've done this for a lot of things: dates, times, measurements, etc. Heres an example: class ActionView::Helpers::FormBuilder include ActionView::Helpers::TagHelper include ActionView::Helpers::FormTagHelper include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::CaptureHelper include ActionView::Helpers:

How do I make global helper functions in laravel 5?

南楼画角 提交于 2019-11-28 04:08:42
If I wanted to make a currentUser() function for some oauth stuff I am doing where I can use it in a view or in a controller (think rails, where you do helper_method: current_user in the application controller). Everything I read states to create a helpers folder and add the function there and then that way you can do Helpers::functionName Is this the right way to do this? Whats the "laravel way" of creating helper functions that can be used in blade templates and controllers? Create a new file in your app/Helpers directory name it AnythingHelper.php An example of my helper is : <?php function