ASP.NET MVC Yes/No Radio Buttons with Strongly Bound Model MVC
If you’re using MVC 3 and Razor you can also use the following: @Html.RadioButtonFor(model => model.blah, true) Yes @Html.RadioButtonFor(model => model.blah, false) No
If you’re using MVC 3 and Razor you can also use the following: @Html.RadioButtonFor(model => model.blah, true) Yes @Html.RadioButtonFor(model => model.blah, false) No
The whole answer for Rails 3, 4 and 5 is: If cache_classes is off (by default it’s off in development, but on in production): Rails.application.eager_load! Then: ActiveRecord::Base.descendants This makes sure all models in your application, regardless of where they are, are loaded, and any gems you are using which provide models are also loaded. This … Read more
Another reason you might get this error is if you use the same model in different files but your require path has a different case. For example, in my situation I had require(‘./models/User’) in one file, and then in another file where I needed access to the User model, I had require(‘./models/user’). I guess the … Read more
You could take your entire server-side model and turn it into a Javascript object by doing the following: var model = @Html.Raw(Json.Encode(Model)); In your case if you just want the FloorPlanSettings object, simply pass the Encode method that property: var floorplanSettings = @Html.Raw(Json.Encode(Model.FloorPlanSettings));
Rails 5.1+ Use saved_change_to_published?: class SomeModel < ActiveRecord::Base after_update :send_notification_after_change def send_notification_after_change Notification.send(…) if (saved_change_to_published? && self.published == true) end end Or if you prefer, saved_change_to_attribute?(:published). Rails 3–5.1 Warning This approach works through Rails 5.1 (but is deprecated in 5.1 and has breaking changes in 5.2). You can read about the change in this pull … Read more
The correct approach in Angularjs is to use ng-value for non-string values of models. Modify your code like this: <label data-ng-repeat=”choice in question.choices”> <input type=”radio” name=”response” data-ng-model=”choice.isUserAnswer” data-ng-value=”true” /> {{choice.text}} </label> Ref: Straight from the horse’s mouth
Multiple attributes can be connected with an and: GroupMember.find_or_create_by_member_id_and_group_id(4, 7) (use find_or_initialize_by if you don’t want to save the record right away) Edit: The above method is deprecated in Rails 4. The new way to do it will be: GroupMember.where(:member_id => 4, :group_id => 7).first_or_create and GroupMember.where(:member_id => 4, :group_id => 7).first_or_initialize Edit 2: Not … Read more
The difference is with the callback. The :delete_all is made directly in your application and deletes by SQL : DELETE * FROM users where compagny_id = XXXX With the :destroy, there is an instantiation of all of your children. So, if you can’t destroy it or if each has their own :dependent, its callbacks can … Read more
I’ve opened a similar question in the Doctrine user mailing list and got a really simple answer; consider the many to many relation as an entity itself, and then you realize you have 3 objects, linked between them with a one-to-many and many-to-one relation. http://groups.google.com/group/doctrine-user/browse_thread/thread/d1d87c96052e76f7/436b896e83c10868#436b896e83c10868 Once a relation has data, it’s no more a relation … Read more
From Jimmy Bogard: CreateMap<Foo, Bar>().ForMember(x => x.Blarg, opt => opt.Ignore()); It’s in one of the comments at his blog. UPDATE(from Jamie’s comment Jan 4 ’19 at 11:11:) Ignore has been replaced with DoNotValidate in ForSourceMember: https://github.com/AutoMapper/AutoMapper/blob/master/docs/8.0-Upgrade-Guide.md