All Questions
Tagged with model controller
1,023
questions
98
votes
8
answers
73k
views
How to rename rails controller and model in a project
I started a Rails app and everything works fine. But now, I would like to rename a controller and the associated model:
I wanted to change the Corps controller to Stores and the same (without final s) ...
76
votes
2
answers
13k
views
Fat models, skinny controllers and the MVC design pattern [closed]
I just read a blog post that explains MVC with a banking analogy. I have a few months of experience with web application development with an MVC framework (CakePHP), so I get the basics, but I began ...
42
votes
3
answers
77k
views
Call a model method in a Controller
I'm have some difficulties here, I am unable to successfully call a method which belongs to a ProjectPage model in the ProjectPage controller.
I have in my ProjectPage controller:
def index
@...
39
votes
3
answers
13k
views
Usage of MVVM in iOS
I'm an iOS developer and I'm guilty of having Massive View Controllers in my projects so I've been searching for a better way to structure my projects and came across the MVVM (Model-View-ViewModel) ...
31
votes
2
answers
42k
views
Real example of TryUpdateModel, ASP .NET MVC 3
I can't understand, how to use TryUpdateModel and save the MVC architecture at the same time.
If I am not mistaken, work with datacontexts must be in the Model. So, such code
var db=new ...
26
votes
4
answers
18k
views
What are the Laravel naming conventions for controllers/models/views?
I remember hearing you should name your controllers, models and views in a special way. Either singular or plural. I don't remember which ones to name what though, and i can't find anything about it ...
24
votes
7
answers
9k
views
Where does input validation belong in an MVC application?
I have a MVC application that receives an input from a form.
This is a login form so the only validation that is necessary is to check whether the input is non-empty.
Right now before I pass it to the ...
18
votes
3
answers
22k
views
Passing a model object to a RedirectToAction without polluting the URL?
Here's what I'm trying to do:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(ContactModel model)
{
if (ModelState.IsValid)
{
// Send email ...
18
votes
3
answers
22k
views
Rails validation from controller
There is a contact page, which offers to enter name, telephone, email and message, after that it sends to an administrator's email. There is no reason to store message in DB.
Question. How to:
Use ...
17
votes
2
answers
31k
views
Is the Rails update_attributes method the best choice for doing an update of a model in the database?
def update
@album = Album.find(params[:id])
if @album.update_attributes(params[:album])
redirect_to(:action=>'list')
else
render(:action=>'edit')
end
end
A Rails 1.1.6 ...
14
votes
4
answers
15k
views
MVC - which methods should be in Model class except set/get members?
Should methods that manipulate the Model class members be implemented in the Model or in the Controller? Does it depend on how "heavy" this manipulation is ?
By "manipulation" I mean:
get a class ...
12
votes
5
answers
7k
views
Difference between Controller and Model in MVC
I'm little confused about controller and model in MVC framework (codeIgniter). Its clear to me that controller methods calls the views and Model methods interact with database.
However, I'm little ...
11
votes
3
answers
8k
views
Can a controller catch an exception thrown from a model?
Well, it is technically possible, but would this break the MVC architecture?
I'm not sure whether this type of communication is recommended between both controller and model. I will describe it using ...
11
votes
2
answers
6k
views
Grails: How do I forward an entire model from one controller to another?
How do I pass an entire model from one controller to another without using a redirect?
10
votes
5
answers
5k
views
Rails: Skinny Controller vs. Fat Model, or should I make my Controller Anorexic?
I know similar questions have been answered before - such as:
Where should logic go
where to do certain tasks, etc.
But I have a more specific question - How far should I take this axiom: keep ...
10
votes
3
answers
1k
views
Model associations problem: NoMethodError: undefined method `extensions' for #<Hash...>
I'm currently upgrading my rails 5.2 app to rails 6.0 while following the upgrading guide.
Everything seems to work perfectly fine until I've encountered an error when one of my user classes (label or ...
10
votes
6
answers
4k
views
MVC: Where should I format data?
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? ...
10
votes
3
answers
11k
views
Route for a controller without model in rails 3
I have a controller named BaseController that inherits from ApplicationController whitout a model associated but it has ping method that just respond with a message to inform that everything is OK.
...
9
votes
3
answers
16k
views
how access to helper "current_user" in model rails? [duplicate]
I need to call current_user (define in ApplicationControler like an helper), in my User model.
I test ApplicationController.helpers.curret_user but not works:
irb(main):217:0> ...
9
votes
1
answer
4k
views
laravel do I need a Model and Controller for every single table?
I know this is a duplicate question but i think it will help others because there are a lot of similar apps that have these kind of table relationships:
So the question is what would be the optimal ...
9
votes
3
answers
13k
views
Pass a variable from controller to view
I do a simple blog on rails.
I have a Post model and a Comment model.
When you create a comment, if comment is not valid, i want to show the error.
How do I do?
model Post:
#/models/post.rb
class ...
8
votes
3
answers
24k
views
Laravel: Create an API Controller, model and migration in one line
This is what I use at the moment to create Controller and Model
php artisan make:controller API/name_of_controller --api --model=name_of_model
then create a migration
php artisan make:migration ...
8
votes
1
answer
6k
views
MVC3 Publishing, why models/controllers don't get published
I am attempting to publish an MVC3 Site in Visual Studio 2010 using the "File System" publish method. The MVC site does not work, but I'm almost positive that this has something to do with my current ...
8
votes
1
answer
15k
views
can't write unknown attribute `scrapbook_entry_id'
Attempting to add data to a join table of scrapbook_entries which has_one :scrapbook and has_one :recipe.
:recipe and :scrapbook already exist. I am trying to add them to link them with the ...
8
votes
3
answers
3k
views
Why is auth typically in the Controller in MVC?
I've been doing a lot of tutorials for different MVC frameworks, and it seems very typical for Authorization to take place in the Controller. Why?
My thought is the Controller should only be used to ...
7
votes
4
answers
12k
views
Zend Framework, run query without a view?
I am currently building a small admin section for a website using Zend Framework, this is only my second time of using the framework so I am a little unsure on something things. for example are I have ...
7
votes
3
answers
15k
views
Rails - Is there a way to update a single attribute?
I was just wondering, I have a model that, besides the id's from other models (FK), it has a single attribute boolean. I want to know how can I create a button that changes this boolean and just that
...
7
votes
2
answers
10k
views
EmberJS, polling, update route's model, re-render component
I've been looking for mechanism to update the model of a Route, and has the Component (called from within the template associated with that route) reacts to that event, and re-render itself.
So I ...
7
votes
1
answer
7k
views
MVC - do I need to use Controller in the View?
As I know in the standard implementation of the MVC we pass Controller and Model to the View
But Im a little bit disagree with this idea. I dont want my view to know about both controller and model (...
7
votes
1
answer
27k
views
The action could not be found for controller
Having gone through my code I have a separate problem from my original question and rather than writing a new question. I will leave the old part at the bottom of this and post the new problem here. I ...
7
votes
5
answers
1k
views
What's the correct place to share application logic in CakePHP?
I guess simple answer to the question would be a component.
Although I agree, I feel weird having to write a component for something so specific.
For example, let's say I have a table of users. When ...
7
votes
2
answers
4k
views
MVC Model is null in OnExecuted action filter ... or a more elegant way to set the model?
I have an ActionFilter with an override on the OnActionExecuted method. The filterContext.Controller.ViewData.Model is always null on a POST operation. I did find the following article that seems to ...
6
votes
6
answers
16k
views
Reverse order of display of blog entries and comments, Ruby on Rails
I am new to rails so could use some help here. I have followed several tutorials to create a blog with comments and even some of the AJAX bells and whistles and I am stuck on something that I hope is ...
6
votes
3
answers
3k
views
MVC PHP - Sending mail from Model
I am having problem to figure whenever I should send mail from the Model or the Controller. The thing is In the controller i use like
This is regarding PHP.
In Controller:
if (Post::get()){
$...
6
votes
2
answers
42k
views
How to create custom MySQL queries in CakePHP?
I am trying to create my own MySQL queries in Cakephp.
This is my LocationsController.php:
<?php
App::uses('Location', 'Model');
class LocationsController extends AppController
{
public $...
6
votes
1
answer
4k
views
Laravel 5.2 understanding "fat model, skinny controller"
I'm trying to understand how to use "fat model, skinny controller" in Laravel 5.2. Basically, I mostly understand the why, and the what, but not the how. I've been Googling for a while, and I have ...
6
votes
3
answers
5k
views
What is the advantage of Model-View-Controller (MVC) over Model-View?
Could anyone give an example of why it would be advantageous to use MVC instead of a simpler Model and a View only.
Note: whether it's called MVC or MVP (Model-View-Presenter), I'm talking about the ...
5
votes
3
answers
7k
views
Detecting changes in the model; php yii framework
I'm creating an audit trail module that i will put in a larger system; and i've created a table to store the trail entries , as an "auditor" what i want to see the currently logged on user, the page ...
5
votes
2
answers
53k
views
Get checkbox values in controller mvc 4
I am trying to retrieve the checked checkbox value from a checkbox list without any success , below is the code which i have tried:
Model
[DisplayName("Gender")]
public IList<SelectListItem&...
5
votes
2
answers
3k
views
Grails - Controller chain and model disapearance
I am trying to use the chain feature to call an other method and render a merged model.
This is how I call the chain:
Controller: emailToNotify, Method: sendEmailConfirmation
if (someCommandObject....
5
votes
5
answers
4k
views
Repository in Controller or Model?
I've been working through the NerdDinner Tutorial and most of it makes sense. What I'm not sure about is why the Repository is used directly in the Controller and not the Model objects. For instance, ...
5
votes
3
answers
3k
views
Using MVC, how should one handle communication between Views? Between Models?
Question number three in my quest to properly understand MVC before I implement it:
I have two cases in mind:
The primary application
window needs to launch the
preferences window. (One View
...
5
votes
6
answers
6k
views
Redirect doesn't work laravel 5
Routes:
Route::group(['prefix'=>'admin','middleware'=>'auth'],function(){
Route::get('/',['uses'=>'Admin\IndexController@index','as'=>'adminIndex']);
Route::resource('/cat-n-cat','...
5
votes
2
answers
8k
views
Accessing ASP.NET MVC Model Data from external Javascript file
I'm trying to use JQuery's $.getJSON to access Model data from the Controller, and build a JSON object in the javascript to use as the user adds and removes items from a list. All JS is done in an ...
5
votes
1
answer
3k
views
Should you handle session data in a controller or a model for an MVC framework?
I am working with an MVC framework (specifically, PHP's CodeIgniter). I am trying to follow "best practices" as much as possible, but I don't have much experience with MVC. Is it bad practice for me ...
5
votes
1
answer
8k
views
How to load Model into a controller in MVC
I am working on building a lightweight MVC, mainly for the learning process but I would like it to be good enough to use eventually.
Below is a basic example/demo of how a basic controller might ...
4
votes
3
answers
14k
views
How to use more than one model in a CakePHP controller
I have created a registration form and I send data to the controller.
I want to insert this data to 3 different tables (models).
How can this be achieved?
4
votes
1
answer
3k
views
Phalcon: the order of 2 functions "initialize" and "onConstruct" in Controller and Model
I check myself and see that, the order of execution on Controller is "onConstruct" then "initialize", while on Model is "initialize" then "onConstruct".
So why the order of execution of these methods ...
4
votes
3
answers
6k
views
Rails: Pass parameter from view to controller
I have the following models in rails :
class Task < ActiveRecord::Base
attr_accessible :description, :name, :project
belongs_to :project
validates :name, :presence => true
end
class ...
4
votes
2
answers
1k
views
In MVC frameworks (such as Ruby on Rails), does usually Model spell as singular and controller and view spell as plural?
I usually see Ruby on Rails books using
script/generate model Story name:string link:string
which is a singular Story, while when it is controller
script/generate controller Stories index
then the ...