Questions tagged [controller-action]

51 questions
3
votes
1 answer

Unit Testing Action Parameters in the WebAPI

I'm writing some unit tests for WebAPI controllers, and one of the aspects that I want to assert is that the parameters match. I've followed the method used in Filip Wojcieszyn's blog, which is working fine, but I'm now looking to extend its…
awj
  • 7,482
  • 10
  • 66
  • 120
2
votes
3 answers

Change the url based on current_user - ROR

Say for instance I have a posts controller that currently has a method user_posts which shows all of the posts that are associated with the user with the associated id as so: def user_posts @user = User.find(params[:id]) @posts =…
Dylan L.
  • 1,243
  • 2
  • 16
  • 35
2
votes
2 answers

How to support multiple forms that target the same Create action on the same page?

I want to have two separate forms on a single create page and one action in the controller for each form. In the view: <% using (Html.BeginForm()) { %> // Contents of the first (EditorFor(Model.Product) form. <% }…
randomguy
  • 12,042
  • 16
  • 71
  • 101
2
votes
2 answers

Using a filter to execute a different action?

I want to avoid having lots of if Request.IsAjaxRequest() in my controllers. I was thinking that if I could condense this logic to an ActionFilter it would be easy to adopt a convention in my application to provide a second action for any request…
Kirschstein
  • 14,570
  • 14
  • 61
  • 79
2
votes
1 answer

How to test a controller action that does not exist?

There are only two actions accessible in the ProductsController: # /config/routes.rb RailsApp::Application.routes.draw do resources :products, only: [:index, :show] end Tests are set up accordingly: #…
JJD
  • 50,076
  • 60
  • 203
  • 339
2
votes
1 answer

How to test a forwarded request with PHPUnit in Zend Framework 2?

I had a simple controller action class CatalogController extends AbstractActionController { public function indexAction() { return new ViewModel(); } // ... } and a unit test for it: class CatalogControllerTest extends…
automatix
  • 14,018
  • 26
  • 105
  • 230
2
votes
1 answer

How to pass controller name in controller action of some other controller?

I have a SQL query where I want to pass controller name as one of the where clause compare parameter. And there are many controllers within the application. Depending on the controller name there will be different result of query to be executed. So…
Krish
  • 43
  • 1
  • 13
1
vote
3 answers

ASP.NET MVC3 : ActionMethod with same name and different arguments for List and Details view

I have a ProdcutsController where i have 2 Action methods. Index and Details. Index will return list of products and Details will return details of a selected product id. So my urls are like sitename/Products/ will load index view to show a list…
Happy
  • 1,767
  • 6
  • 22
  • 26
1
vote
1 answer

Is a ASP.NET MVC controller action faster/more efficient than a HttpHandler?

I'm trying to create a simple lightweight server side redirect which inspects the client's User-Agent and redirects to a website for a given browser. For example: if(Request.UserAgent.contains("Firefox") { //redirect to www.yahoo.com } else…
HOCA
  • 1,073
  • 2
  • 9
  • 20
1
vote
0 answers

Best practice for handling wrong HTTP verbs

We have the recurring issue with either users reloading pages or attacks sending: POST to GET actions GET to POST actions. Especially the hacking part floods our logs with errors while trying all kind of url parameters... Obviously this results in…
M R
  • 15
  • 2
1
vote
1 answer

Problem implementing edit/update functionality for model

When I try to edit an instance of my Job model, the attributes I'm trying to update are set to Nil. I've tried using the regular form_for helper instead of simple_form because I didn't know if simple_form required extra info such as what action and…
1
vote
1 answer

How to test an action's output in ZF2/ZF3?

How to catch the (ViewModel) output of a controller action in ZF2/ZF3? Background: I'm writing some integration tests for a Zend Framework 3 application (just migrated from ZF2). I'm using PHPUnit v6.2.2 and Zend\Test v3.1.0. I want to test the part…
1
vote
1 answer

ASP.NET MVC - comma separated double as parameter of controller action

I have the following controller action: public ActionResult AjaxQuantity(int productId = 0, double quantity = 0d, int periodId = 0) { ... } and appropriate ajax request: function Quantity(productId, quantity, periodId) { $.ajax({ …
user3641858
1
vote
3 answers

Rails render and pass query param

This is in the login action. I'm trying to adapt it to send back a return_url query param, and i'm failing with a simple render. Prior: respond_to do |format| format.html { flash.now[:error] = error render } Attempt 1: …
jahrichie
  • 1,215
  • 3
  • 17
  • 26
1
vote
1 answer

ASP.NET MVC ySlow Add Expires Headers for dynamically served script

I am serving Javascript vai a controller method that looks like this: [OutputCache(Duration = 120)] [Compress] public ActionResult JavascriptFile(String scriptName) { string content; if (HttpContext.IsDebuggingEnabled) { …
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228