As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I like to use the strongly defined routes like
#Html.RouteLink("Home", RouteName.HomeIndex)
Why there is no equivalent helper for child actions? I don't like the actual #Html.Action(actionName, controllerName, routeValues) helper.
In addition, the performance would be better. There is no need to check all routes internal in the RouteCollection.
Contribute your idea and even the helper at http://aspnet.codeplex.com/ - it's open source.
The answer to Why isn't there one is that either:
Nobody thought of it yet
Someone thought of it but didn't do anything about it
Someone thought of it but thought better of it - for example because a route can be very general and you would need to supply controller, action and routevalues for most routes, which means the Action helper works fine.
In terms of performance, I've not had any problems with the performance of Html.Action so you might want to measure it before you get too concerned about optimising this aspect of the framework.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I m new to ROR3.0 I was read a lot place saying that is "this code is DRY" or something related to DRY
I want to know how to make a code DRY ?
Is it necessary my code should be DRY?
DRY stands for Don't Repeat Yourself. If it's possible, it's good practice to use DRY in most coding environments to make it easy to maintain going forward (and stop your copy-paste keys getting worn out!)
I'd suggest wherever code is repeated to extract the common code and extract into a method.
The wiki below is a good place to see where a lot of these shorthand expressions came from:
http://c2.com/cgi/wiki?DontRepeatYourself
In this case, 'DRY' simply means 'Don't Repeat Yourself'. This simple guideline leads to writing smaller, better decomposed methods which can be reused in several contents. This in turn leads to easier maintenance, better testability etc.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I know that using plural for controllers name is the right way in Ruby, but in some cases using singular for controllers name is more appropriately. For example
http://foobar.com/admin/login/
http://foobar.com/admin/dashboard/
http://foobar.com/profile/
I think you get what I mean.
So which are the best practices of using singular for controllers names ?
Any example will be appreciated !
If you don't need the whole scaffolding, for example you probably have no admin model, then you can just generate a controller with a singular name.
rails g controller admin
Then, you need to take care of the routing.
match 'admin/login' => 'admin#login'
Rails favours convention over configuration, so it means that controllers are ALWAYS using plural, table names also, whereas models are always using singular, with an uppercase at the beginning.
I would strongly advice you to stick to these conventions, that's best practice and in the foundation of the Rails framework
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Thought I would put this out there before I embark on my own research.
In a current MVC 4 app, I am looking for a way to track/audit visitors. I am looking for a way to:
Record a record on each site request.
Record will include things like logged in user, session id, requested page, page coming from, etc., etc.
Action methods will be decorated with an attribute to trigger the creation of that record, so we can specify exactly which action methods get logged.
Anyone attempted or heard of anything like this?
Thanks in advance for any replies.
An ActionFilter seems to be the way to go. I have an example of a similar requirement that I'd be willing to send you, let me know.
You should consider writing a base controller that all your controllers will inherit from and then do all the logging in there.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
In Rails, we offen write a lot of code in our models such as class methods, plugin methods, named_scopes, callbacks... I am wondering if there is a good pattern to organize the sequence. I saw the best example in a presentation before, but now I forgot.
Anyone have suggestion? Thanks
There is no set way... If you are using a scope (since Rails 3, named_scope is deprecated) that relies on a method, it has to be defined after the method in the model. It's possible to mix and match and sometimes it's necessary to do so.
It doesn't affect load time or efficiency to the best of my knowledge
I'm pretty OCD when writing ruby, so I have a very opinionated answer to your question. I created this gist as an example of the structure we use.
I wrote about that a while back as part of my style-guide:
acts_as_good_style.
YMMV as to what the "best" grouping/ordering is, but if you'd like my take it's there under the "Model idiom" section
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I'm making a fairly basic rails app and I was wondering what's the best way to strip undesirable html from text field (basically, all I'm looking to preserve are links and no more than 2 linebreaks).
Currently, I'm stripping all html and using simpleformat, since it seems to be less overhead than using RDiscount and Markdown/Textile, but this is not really an ideal solution.
Probably the sanitize helper.
Module
ActionView::Helpers::SanitizeHelper
Another option is Sanitize gem.
http://wonko.com/post/sanitize