Rails couldn't find a valid model for Preferences association - ruby-on-rails-7

I'm trying to add new record to my DB, but I got this error:
This is my schema.rb:
And this is my method create:
And this is my form to add a new record:
The param is sending correctly, but when I click on Upload button, nothing is happen, and if I try to add the record from the rails console, I got the error of the first image. I'm a new dev of RoR, someone can help me please?, Thanks!!

Without looking at the related models and their associations nothing is clear, because, it seems like your model associations are causing this error.
Model associations depict the relations between models (if its one-one, one-many and such) known as inheritance, very important concept in any object oriented programming. this is the way we implement it in rails
Go through this documentation.
It might help you get better understanding of rails associations.

Related

Create record via client script in a relation model in App Maker

Could someone point me to documentation that shows how to create a record in a model with one to many relation via client side script.
Thanks in advance!
There are two ways of creating a new record.
1. Via a client-side script
You can do this by calling a createItem function from a widget. This link might help with that.
2. Via a server-side script
You can do this by directly creating a new record, assigning it to the relation of a model and then saving that model. This link might help with this method. By the way, it's easier to do this in a server-side script, as the guide itself says.
Since you just requested the link to official documentation, I've limited my answer to links only. Please feel free to ask if you need clarifications!

ASP.NET Entity Framework, Add Table to Model

So I've found similar questions, but could really use some help! I have an Entity Framework Application with a whole bunch of tables. I've had to add a new table, and I understand that I can get the model to update using the wizard from .edmx file. The problem is that I REALLY don't want to udpate all of the other models. I've added validation for my models as they're being used in forms, regenerating these models will get rid of all that code. Any suggestions? Thanks a lot.
You won't be able to preserve the changes you made to the auto-generated classes as part of the .edmx.
This may not be the answer you want to hear, but your situation is one of many reasons to use different classes for your user submitted data (i.e. web form in your case).
A few other reasons you should separate your models:
Prevent over-posting which could result in bad data or even security issues
Keep your data models clean and simple by avoiding having UI specific properties (e.g. SelectList which is an object to help populate <select> elements, but doesn't need to be part of the database)

Web API Help Samples - C#

ASP.NET Web API has an easy install Nuget help page with sample generator. It's easy to get it to generate and display sample requests, but not so easy it seems to get it to display sample responses (httpsampleresponses) so that when developers look at the help page they'd see examples of generated responses / not static/typed in responses, but actually generated. I've seen it done before on another project, but still having trouble figuring out how to do it. MSDN's YAO has a good blog but it's just not getting me all the way to success for some reason.
From what I've seen work live and based on what there is to read about it online, it's definitely in getting the HelpPageConfig file right in terms of the config.SetSampleResponses() set up. I've discovered the configuration file that sets the parameters for the SetSampleResponses() method, but still, nothing I try is working. It was suggested to me that I should create a custom type and use extension methods, but getting that to correspond and display what I need hasn't happened yet. I can get it to compile without errors, but it still doesn't show the generated response sample on the page. It was easy with the SetSampleForType piece to get a section to show up in the requests section, but it's the response part that has given me trouble.
Has anyone out there done this with the SetSampleResponses() successfully and is there any kind of trick you can clearly define for getting it to work? Do you have any tips on setting up a specific generic type and making that work?
I'm thinking this must be something really simple and I'm just not clicking to make it happen....
Thanks for any potential info...
SetSampleResponse extension on HelpPageConfig is for statically defining samples for you action.
config.SetSampleResponse("\"Hello World!\"", new MediaTypeHeaderValue("application/json"), "Values", "Get", "id");
if you are looking for generated sample for a particular type, have you tried using SetSampleObjects extension which allows you to set sample objects for different types and this same object is used in all cases where that particular type is returned from an action.
config.SetSampleObjects(new Dictionary<Type, object>
{
{typeof(string), "Hello World!"}
});
Could you share more specific(code) details as to how you are using SetSampleResponse extension?

PersistentBag exception in Orchard

I'm trying to adapt the guide http://docs.orchardproject.net/Documentation/Creating-1-n-and-n-n-relations for creating an N-to-N relation in my Orchard module, but I get an exception "unable to cast NHibernate.Collection.Generic.PersistentGenericBag`1[ArealAds.Models.StreetAreaRecord] to System.Collections.Generic.List`1[ArealAds.Models.StreetAreaRecord]". I don't fully understand what's going on behind the scenes so it's hard for me to debug. What is the likely cause of this error? Where do I start looking?
You should change the type of the related item collection from List<T> to IList<T> (or more generic IEnumerable<T>), as NHibernate cannot map the property to it's internal item collection (which implements IList<T>).
See similar issue.
You did not correctly follow the guide. There is an example of an n-n relationship in the document and it works. Without seeing any of your code, it's hard to say what went wrong, but it has to be different from the tutorial somehow. Another example you can look at is the bundle part in this module: https://bitbucket.org/bleroy/nwazet.commerce. it establishes a n-n relationship between content items.

I am needing to change the table schema without reloading the app domain (EF Model Caching Issue)

I have a custom implementation of a multi tenant code first system basically SQL Schema Divisions of the tenants. I am using the ToTable method to map the schema correctly on the first call, but as I have read about the model being cached changing the schema on the second call do a different tenant does not work. Is there any ways in EF 4.1 to disable the caching or to rebuild the model every time.. Yes i know this is not great for performance. Thanks for any help..
Although it is an old question, but for all those who face this issue and end up finding this question for a possible solution. Here it goes...
Initially caching could be turned off by setting the "CacheForContextType" property of the ModelBuilder to ‘false’ in the OnModelCreating method. This method is defined in DBContext as virtual and needs to be overridden. But in EF 4.1 this property has been removed, since model creation is an expensive process and the Microsoft team wanted to promote a better pattern. Check this link
It seems like the Build() command on the ModelBuilder is what you're looking for.
modelBuilder.Build().Compile().CreateObjectContext...

Resources