controller

MVC: Where should I format data?

Hi, I get data from Model (an array with data) and I need to display with a specific format. I need to iterate over the array, format the data and then display it. Where should I format data to display? In Model, Controller or View? Thank you. ...

What should my ASP.NET MVC Controllers represent - "real world" application.

I have an established web application built as an ASP.NET 3.5 Web App. We recently modified it to mix MVC into the app for some new functionality. Now that it's in there, we want to leverage MVC wherever possible to begin to "transform" the app from clunky webforms to a more maintainable and testable MVC app. The question that just cam...

Shared 'per request' storage for ASP.NET MVC controllers

In a standard ASP.NET webforms project, if I have a several user controls on a page that require the same data I'd tend to have the first user control put the data in the HttpContext.Current.Items collection so it was available for all the others. What's the nearest equivalent to this for a ViewResult on an MVC controller that's used mu...

In Rails, any way to use app/helpers/foo.rb methods in Controller vs in View?

It seems that those helpers in app/helpers/foo.rb can be used in View, but cannot be used in Controller? In some cases, different controllers may need to use the same method but just pass in a different parameter, so in that case, won't it make sense to use a helper in a controller? ...

Params becomming nil

Had some old code that on some condition would modify params. I believe it was working before (not 100%). We are now getting params set to nil whether or not the condition is met. The culprit is within the condition, I perform a params = tmp.dup. Even when the condition is false, this is causing an error in the update action. I was abl...

Rails controller - redirect to website after create?

Hi Everyone, I am working on a basic app that has a public facing form (for enquiries) that anyone can fill in and submit. The results are then stored for the company to do what they want with. I have made sure that if the user is not logged in they can only access the create page, but once they submit the form, as expected, they are t...

reference data is lost when form fails validation in spring3 annotation based controller

I'm doing the spring 3 annotation based controller thing. Problem is, when it fails validation, the reference data is lost, namely the countryDivisions stuff. I didn't put it in the form because its not user editable data, and the orthodoxy here is that only user-editable data goes in the form. Do I have any other choice? @Controller pu...

How do I set a custom view engine from within the controller?

I'd like to set a custom view engine from within a controller that is specific to that controller. Or is there some configuration-based way to tell the framework to use the custom view engine only for that specific controller? ...

CakePHP: COUNT function and model joining help

Hi, I'm trying to join tables to get a count on a field but am having trouble figuring out how to do it. here are my tables: tags id INT tag VARCHAR project_tags id INT project_id INT tag_id INT projects id INT ... I want show in my view something like this: [tags.tag] x 23 [tags.tag] x 12 ... Now I'm no S...

Can You Access Model Data in Controller in CakePHP?

This is probably a dumb question, but I can't find a definitive answer anywhere. Is it possible to access model data in a Controller, and if so, how? I tried the following: $this->set('mydata', $this->Model->find('all', 'conditions' => array('id' => 'someID'))); And accessing it via this in the controller: $mydata['Model']['field'] ...

Question about building own (PHP) MVC framework

Hi people, At this time I want to build a MVC framework. Everything is going fine but now I got a problem between controller and view. Hope you can help me. My MVC is not so different from MVC, it uses the same concept, but technically I got an issue. The question is: how to take data from the controller once the view is loaded? Bear ...

In Grails, how do I return to the calling current view from a controller?

Below is a very simple controller with a "search" action that is fired from g:submitButton in a gsp file. My question is, instead of redirecting to the "index" action and view, how do I return to the view that contained the submit button that called this controller's search action? class DefaultSearchController { def searchableServi...

In Ruby on Rails, what is a good way to get subclass's name in a base controller class?

If both ProductsController and CategoriesController both inherit from GenericController, what is a good way to get the string products in the base class when the URL is pointing to the Products controller? (in this case, the base class's index action is doing things that would need to use the string products to query the database) self...

In Ruby on Rails, cannot render :controller => 'generic', :action => 'top_pages' but need to use :template => 'generic/top_pages'?

it seems that the :controller option doesn't do anything? Won't specifying the whole path be a little bit lower level than specifying using :controller? ...

Can I get the name of the current controller in the view?

I am rather certain this is a stupid question, but I can't find the answer. Is there a way to figure out what the current controller is from within the view? For an example of why I would want to know this: if several controllers share the same layout, I may have a part in the layout ERB file where I want to highlight the current page'...

Form not working on index page

I'm using Spring 3 and Eclipse. The weirdest thing happened, when I was trying to make a form on index page: all I got is neither plain target or binding result for bean name (commandname) error...but when I copy EXACTLY THE SAME form to other .jsp-file and THE SAME controller method, it works fine! Can anyone tell what it is? ...

Grails Controllers adding instances

Alright I asked a question before but wasn't quite sure about it. So I went ahead and waited till now to ask again. Main Question How do I add a new instance of the domain through the controller? I created a function named gather to read a file with data and then create a new Book with the specific information, however it is not adding...

Custom/manual associations in a Rails controller

I have four models with the following example: User has one A, B, or C. User.user_type = "A" User.user_type_id = 12 In combination, the user_type and user_type_id identifies the table and record a particular user is tied to (in this example our user is connected to record #12 in table A). On the user/new form, the user decid...

dynamically mapping roles to controllers in ASP.Net MVC

I am currently hard coding the authorized roles in the filter in my MVC applications like so: [Authorize(Roles = "Administrator,Manager")] I'd like to eventually have a way to map the roles to each controller, so that the site admin can handle assigning what roles can perform each set of actions. string roles = DoSomethingToGetAllowa...

Why doesn't this view display posts in descending order? (simple question)

home_controller.rb: class HomeController < ApplicationController def index @title = "tags" @posts = Post.tag_counts.collect do |tag| Post.tagged_with(tag).first end @posts.flatten.uniq @posts = @posts.paginate :page => params[:page], :per_page => 8 end end index.html.erb: <%- for post in @posts -%> ...