applicationcontroller

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

巧了我就是萌 提交于 2019-12-17 21:52:40
问题 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

Using “ApplicationController.new.render_to_string” in a Rails api app (config.api_only = true)

蹲街弑〆低调 提交于 2019-12-11 06:28:28
问题 I have a Rails 5 app build as an api app: # config/application.rb module MyApp class Application < Rails::Application config.api_only = true end end In one of my controller actions I need to render some Ruby flavoured html, and then serve it back in the json response. A standard Rails app do this: # app/controllers/my_controller.rb def my_action html = ApplicationController.new.render_to_string("my_erb_or_haml_file", locals: {foo: "bar"}, layout: false) render :json => {html: html}, :status =

Rails 3.0 Engine - Execute code in ActionController

不羁岁月 提交于 2019-12-09 04:27:43
问题 I am upgrading my Rails plugin to be an engine that works with the latest 3.0RC1 release and I'm having a bit of trouble figuring out the best (and most correct) way to extend ActionController . I've seen this post by DHH and this question here on SO, but my question is more about how to properly call code within the ActionController . For instance, I need to call the following within my engine's controller: class ApplicationController < ActionController::Base helper :all before_filter

How do you route an action to the application controller in Rails 3?

匆匆过客 提交于 2019-12-03 07:10:02
问题 I am using the gem rails3-jquery-autocomplete and had no problems with it, however I have now moved my autocomplete form into the application template and therefore the ajax calls are now being dealt by the application controller, so my routes have changed from: home/autocomplete_category_name and now need to have the home removed and the path from: home_autocomplete_category_name_path to: autocomplete_category_name_path Anybody got any ideas? Still learning the ins and outs of Rails so this

Rails 3.0 Engine - Execute code in ActionController

丶灬走出姿态 提交于 2019-12-03 01:48:22
I am upgrading my Rails plugin to be an engine that works with the latest 3.0RC1 release and I'm having a bit of trouble figuring out the best (and most correct) way to extend ActionController . I've seen this post by DHH and this question here on SO, but my question is more about how to properly call code within the ActionController . For instance, I need to call the following within my engine's controller: class ApplicationController < ActionController::Base helper :all before_filter :require_one_user after_filter :store_location private def require_one_user # Code goes here end def store

How can I extend ApplicationController in a gem?

徘徊边缘 提交于 2019-11-29 01:21:21
I thought I'd come up with a slick way to extend ApplicationController in a Rails 3.x gem. In my gem's lib/my_namespace/my_controller.rb , I had: class MyNamespace::MyController < ApplicationController before_filter :some_method after_filter :another_method def initialize # getting classname of the subclass to use for lookup of the associated model, etc. # and storing the model_class in an instance variable # ... end # define :some_method, :another_method, etc. # ... private attr_accessor :subclass_defined_during_initialize # etc. # etc. end but when the Gem is loaded, app/controllers

“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

How can I extend ApplicationController in a gem?

邮差的信 提交于 2019-11-27 15:50:27
问题 I thought I'd come up with a slick way to extend ApplicationController in a Rails 3.x gem. In my gem's lib/my_namespace/my_controller.rb , I had: class MyNamespace::MyController < ApplicationController before_filter :some_method after_filter :another_method def initialize # getting classname of the subclass to use for lookup of the associated model, etc. # and storing the model_class in an instance variable # ... end # define :some_method, :another_method, etc. # ... private attr_accessor