Questions tagged [actioncontroller]

ActionController is the main controller class in Ruby on Rails.

ActionController is the main controller class in Ruby on Rails.

424 questions
2
votes
1 answer

Explain the difference between ActionController#respond_to and ActionController::respond_to

I've read the documentation, and it confuses me every time, just because it doesn't answer some basic things. I realize the main purpose of the class method ::respond_to (which is normally used at the top of the controller) is for use in…
mltsy
  • 6,598
  • 3
  • 38
  • 51
2
votes
2 answers

How rails render works in controller? Why something it doesn't use layout?

I tried to write render in an action, but layout behavior is different, why? def show # assuming we have a partial in app/views/shared/_panel_show.html.erb #render "shared/_panel_show" # have layout #render "/shared/_panel_show" # without…
allenwei
  • 4,047
  • 5
  • 23
  • 26
2
votes
1 answer

How do you stream from a database table using ActionController::Live?

Setup: In my environment, a Java program writes to a PostgreSQL database table called readings continuously, say every second. I am building a rails app that connects to the same database and displays those readings. Here is a picture of the…
2
votes
2 answers

Avoiding repetitive "content_for" in views

I have a submenu placed in my layout wich differs from controller to controller, but not between each controllers method views. What I am currently doing is the following: <% content_for( :submenu ) do %> <%= render :partial =>…
Felix Andersen
  • 1,381
  • 2
  • 14
  • 26
2
votes
1 answer

Rails controller testing - Validation errors do not raise a HTTP error response

I have an ActionController derived Test which sends a 'post' request to the controller under test with incorrect data. The controller tries to create a new object and save it. The model has validation methods that get triggered on save and they…
bhavinb
  • 3,278
  • 2
  • 28
  • 26
2
votes
0 answers

Issue getting variable to pass from Controller Action to Mailer template in Ruby on Rails

I'm having trouble getting a variable filled with text to pass from my controller action "Submit", to my email template. The code listed is to allow you to follow the variable named @message through my app. To start, what I have is a basic "show"…
sabrams
  • 1,128
  • 2
  • 15
  • 28
2
votes
2 answers

Redirect to a specified URL after a POST in Rails

So often I have a form in some webpage that the user submits to a POST, PUT or DELETE action in Rails where I want it to redirect to a specified URL if the submission was a success. I typically make a hidden extra parameter called to with a path…
2
votes
1 answer

Using _url Absolute Links with ActionController full page caching

We have a rails 3 application (3.2.12) on which we wish to implement full page caching (Using ActionController caches_page) We are using _url url helpers everywhere in the application, and this is causing the links in all of the cached pages (in…
silasjmatson
  • 1,814
  • 18
  • 37
2
votes
1 answer

Controller not inheriting before_filter

So I have ApplicationController.rb: class ApplicationController < ActionController::Base protect_from_forgery def decode_email params[:email] = URI::decode(params[:email]) end end and then UsersController.rb: class UsersController <…
Chris
  • 11,819
  • 19
  • 91
  • 145
2
votes
0 answers

How can I test ActionController extensions within Rails 3.2?

I wrote an extension for ActionController::Base in Rails 3.2. Now I want to test it. But because the gem I created is no application it has neither specific controllers nor routes, so I cannot use "get" or "post" to call any action. Is there any…
2
votes
2 answers

How to check if attribute is changing in update action in Rails?

I'm trying to check - if some (language) attribute is changed and if it is equal to some value I need to change it into other proper value. Here is my code: EDIT: def update @website = Website.find(params[:id]) @website.language =…
Denys Medynskyi
  • 2,353
  • 8
  • 39
  • 70
2
votes
1 answer

Object.attribute_changed? not working in Rails controller

I'm overwriting Devise user's registration controller to check if user has changed city and if so, load again the Geokit object in session. session[:geo_location] = User.geocode(resource.city) if resource.city_changed? Problem is that is not doing…
Martin
  • 11,216
  • 23
  • 83
  • 140
2
votes
0 answers

how do I convert a path string to controller + action + parameters?

(I'm sure I've seen the answer to this, but can't find it after many minutes of digging. It should be an easy one to answer...) motivation In the console, you can invoke the get method with a path argument, such as: app.get posts_path(321) This…
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
1
vote
2 answers

Error when removing '::Base' from ActionController

I'm writing a rails application, and in this one controller I need to specify the layout to render due to inheriting from ActionController::Base. In some of my other controllers I just have ActionController and it automatically uses the application…
Kyle
  • 607
  • 2
  • 6
  • 14
1
vote
1 answer

Rails detecting the request type in the controller?

I have a controller which via html shows the user profile, via JSON shows a user hover card w profile info. class UsersController < ApplicationController def show @user = User.where(:id => params[:id]).first return redirect_to "/" if…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012