When I make changes to controller methods, models/view models, I get the prompt to propagate the changes throughout the code base. This is working as intended for C# code. But my views are not updated too, so I end up having to chase down everything manually, which can be a pill with a lot of partials.
Is there something I can do to ease this process (other than not making changes)? I do have Resharper.
The answer is no.
That is normal functioning. The Views must be modified manually.
One thing that will help is to use ReSharper's Find Code Issues. It will point out all views that aren't compiling properly, so at least you will know what Views to look in.
Related
Context
As asked before by others in 2012, see links below, I like to know if my Rails views are covered in my specs/cucs. I know that in 2012 the answer was that there was no solution. I was wondering if there is a solution now in 2014? I searched the web and did not find much, so I fear the answer is the same.
Motivation
I want to know if my cucumber features cover all parts of the API (in this case the GUI). When I add GUI functionality (new view, button, etc) but I somehow forget to add a cuccie for it, I want to get a notification.
So it's not so much that I want to cover everything in my views, but I want to prevent that I unintentionally forget to add a cuccie for new user features. Hence reducing the chances of code not working in production.
Research
I found the following links, mentioned above:
How to test code coverage for Rails ERB templates?
How do I get coverage for view specs with rspec, rails, and simplecov?
A potentially interesting approach that I want to look into is:
Rack middleware to help measure production code coverage
I want to prevent that I unintentionally forget to add a cuccie for
new user features.
The pedantic answer is that you could make sure to write those tests before adding the features (or at least commit them at the same time.) But, that's overly dogmatic and not always realistic.
SimpleCov or another test coverage tool can help you monitor this indirectly, even though it can't measure coverage in views directly (because they're not written in Ruby.)
If you're covering every controller action, model and view helper method, then you're probably in good shape. (This works best if you avoid putting logic in the views wherever possible.)
I am working on MVC3. not sure whether its the right question but it keeps on bothering me always.
I have a generic model used by multiple views. If i make any changes to the model variables for example name change it does not reflect in any of the views nor does it throw any compile time errors. The errors are thrown only at run time.
This can cause a serious issue if model changes are not checked for in each view manually.
Is there any way to overcome this manual changes in the view?
There are two things that can help. The first is T4MVC, although this is really more about making your helpers more compile-time safe. This won't, by itself help. If you also follow these instructions then it will also compile your views and catch most of these errors.
Be aware, however, compiling views can significantly slow the build process.
nope... that is something you must be aware of, when "fixing" your model.
as the model gets evaluated at runtime, just like ViewBag and ViewData, you will have to update changes manually.
i guess you could update the changes with a nice "Search and Replace" though
At my new job, I was given some MVC work. There is only one controller with nine action methods(6 are for ajax rendering) . The page was bit large, so I divided it into small your controls and used render partial to render them. Some user controls were being render through ajax also. Most of the controls are not more like foreach loops and rendering some data from tables, not more 10-15 lines. The main index page passes model to all the controls. My main page looked very clean and easy to maintain.
But my team members are saying, I should put everything in the main page rather than building small controls. Their point is number of files will be a lot, if we start creating controls like this. Also they say if we are not reusing these controls somewhere else there is no point creating them separately.
I would like to know what is better approach for this kind of scenario. Any good links which can help us to understand things better, or any book we can read to clarify our questions.
Help will be appreciated.
Regards
Parminder
As a preface to my answer, let me mention the important value of maintainability. Software evolves over time... and must change to fit the need of the application.
Maintainability in code does not magically appear... Sacrifices (with a touch of paranoia sometimes) must be made in your coding style now, to have the flexibility you'd like in the future.
There may a large page in your project. Some may say that if it works, no need to fix it. But that's looking at it from a short term perspective. You may need some of those UI interfaces in other places in the future. What some persons may do (rather than make partials) is copy that code in the places where they need it - thus causing the same bloat over time that they were trying to avoid.
If you're on the project in the long haul, you'll more fully appreciate the need for flexibility over time. You can see that there are patterns that you'll want to re-use.
My suggestion then: Partials and controls are good things... they are good investments for your ease in the future. If you forecast reusability, that's a good sign for using them.
But use them sparingly. Don't micromanage everything on a page. Some things may be itching to be 'component-ized' but sometimes it's best to SSFL (Save some for later). Like everything in life, balance is important.
Having clean concise code is the way to go. Your code will be alot more readable if you utilize :
sections
templates
partial views
Just remember its always easier to navigate folder structure than to read 100's - 1000's of lines of code.
I recommend watching "Putting your controllers on a diet" by Jimmy Bogard.
Also read "Fat Controllers" by Ian Cooper.
these two links will give you a good idea on how to structure your MVC apps.
I've been developing iPhone apps for a while now and something that's always peeved me is that I haven't found a comprehensive way to organize my application files.
I know that an iPhone project is technically MVC, but it seems like most everything I do is in a ViewController. I notice that as a project goes on, my ViewControllers continue to get more and more bloated and I can't help but think that there has to be a better way than this. I also do some ruby on rails and I like the fact that on that platform there is such a clear separation of concerns and an established way to organize an application.
Has anyone discovered a way that they especially fond of for organizing the application?
Also how do cut back on the view controller bloat?
I agree, just about everything seems to land in view controller classes, and they get unwieldy in a hurry. There are several things you could try:
Create separate classes for delegates, if they don't actually need to be part of the view controller;
Put delegate method implementations into a category, as described here;
Factor out any methods that don't actually interact with the rest of the view controller, and put them in separate classes
Use blocks for asynchronous callbacks when they make sense, because they are often less verbose than explicit callback methods;
Or even just organize your methods carefully and use #pragma mark so Xcode can help you navigate through the file.
This isn't an exhaustive list, of course, and others may have better suggestions.
Is it correct to use partial views for the SOLE purpose of breaking down a more complicated view into separate chunks and therefore making it more readable?
It probably seems a silly question but the reason I ask is that everything I've read about using partial views involves a piece of the UI being re-used in multiple places. In my case the piece of UI being put into the partial view is only used in one place. It is therefore done solely for readability, but I'm not sure if the performance impact of this may outweight the increased readability. Thoughts?
Whilst this is correct there are more uses.
Reusability
Ability to pass pack rendered html
from your controller so you can
append the partial view to the bottom
of containers. Great for jQuery
async calls
Seperation of concerns
Gives developers the ability to work
on different sections of a page w/out
getting in each others way.
Just to name a few.
I think that you shouldn't be worried about performance until it is a real problem, but you should be worried about your code from the first moment. I usually use partial views to simplify the logic or the structure of my views, as you are wanting to do.
Sure, that's an okay use for them. If it keeps the page organized so it's easier to maintain, I think it's fine.
Also, if I'm using caching, I find it easier to have my:
cache "this" do
# render partial
end
I find it easier to read and keep track of things, especially on an overview or dashboard page where there are lots of different parts of the pages that you're including.
I tend to be a bit more conservative. I only use a partial view when I know I'll need to reuse the code or I have multiple complex objects in ViewData that need to be displayed.
There's no right or wrong way here but I have worked on projects where there are a ton of partial views to make things "more simple" and I end up spending forever trying to track down where all the partials are (controller/action folder, shared folder, or elsewhere).
One thing about my approach though is if you have even the slightest thought that the view code may be reused down the line as the project changes use a partial. It will save a bunch of time down the road.
I veto any large and complex view in our projects. Instead, we use RenderAction to extract those pieces of code into smaller chunks/parts. I blogged about it here:
http://eduncan911.com/blog/html-renderaction-for-asp-net-mvc-1-0.aspx
Basically, you move that logic and/or parts into Controllers.
Or, if you are just talking html - then yes, breaking down a view into RenderPartials works too.