I have an app that I have a model that supports multiple addresses, but upfront I only want to allow the user to add/edit one address.
User
----
UserId
Address
----
UserId
Line1
...
I have the following to render the form for adding a new address, but how about existing records? What do I need to add to my configure method in the User form?
$this->embedForm("address", new AddressForm());
Take a look at More with Symfony: Advanced Forms. This chapter outlines a good way to embed multiple forms when dealing with 1-to-many relationships and should more than cover explaining what you need to do.
Related
I have a regular rails app with index, show pages, and forms.
I'd like to allow the administrators of the site to customise the default texts across the site without code changes.
For example, the admins should be able to change a page's H1 tag from "User Index" to "Customer Index", or change a form label from "User Name" to "Customer Name".
I was thinking to create a model called ui_texts that has two fields:
machine_name: string
value: string
Then, I would replace the current hard coded texts with a query like:
Ui_text.where(machine_name:"user_name").value
The admins would have a simple CRUD to edit the ui_texts from the admin interface.
The problem with this approach is that a complex form will generate dozens or even hundreds of database queries to populate all the UI texts.
Even if I index by machine_name, the extra queries will add considerable time to the page load.
I wonder what is the optimal way to achieve such functionality?
You can use i18n to localize your application and set it up to use a database backend. Expect this to take a few hours of your time, it's rather cumbersome.
https://guides.rubyonrails.org/i18n.html
https://guides.rubyonrails.org/i18n.html#using-different-backends
After you set this up it will be trivial to create a CRUD section in your application where users can edit whatever messages they like.
I'm looking for something like an editor but instead of the user editing just a post or page the user can edit the default template layout or view layout for all pages associated to something.
I'll give an example to get my question across because i really don't know what it would be called.
Say for example you have categories. (people, animals, etc..)
Now imagine there is a category of people, each person in the category has the keys 'height', 'weight' and 'age' and each key has values assigned to them (height: 120 cm, weight: 80 pounds, age: 25)
I want the user to be able to edit the layout of the people page (page template or view that each person is displayed on) and be able to add in the keys they want to be displayed on the page.
So say they add the keys ‘height’ and ‘weight’ it will only display the height and weight on every person page, plus whatever pre set text the user added in the template editor for the people pages to display.
I could probably find a good editor that can be customised and change it to my liking but there might already be gems out there made for this.
My question is, is there a gem for basically letting users set templates for record pages.
Even if there is something out there to change views for objects but the user cant set the keys on it, i'd still like to see it because I might be able to add the key/value functionality to it.
Hopefully you understand what I'm looking for.
UPDATE
Ok so i appears I'm after an editor that works with a template engine like liquid or one thats both an editor and template engine.
If you plan on building from scratch, it sounds like it could be done using rails generate scaffold this allows views/models/controllers to create pages for each of your categories.
Then you can use Associations to create associations between your categories.
You can also make different user roles by making a field called "Role" in your Users relation
Otherwise, there are also open-source software Active Admin to manage content for your categories.
EDIT: After looking around I found a gem you can use to have end-users edit your own views, feel free to check out Liquid.
Problem:
I am trying to create an app whereby a person can 'click' on tag buttons that are of different sports preferences (ie: "Running", "Involves Bats"), each of which are tagged to certain sports. So, if the user selects the tag "Involves Bats", then the app will generate all associated sports such as "Baseball", which would have "Involves Bats" as a pre built tag.
What I've Done So Far:
I have added the acts_as_taggable gem
I have created a model for "Sports", that has no controller.
I have in seeds.rb created defined the "Sports" model with names of each sport.
I have a Users controller, where someone can submit email which takes to them to the their user page.
What is Left
I need to tag all preferences (ie "Running") to all potential "Sports". I am having a really difficult time doing this.
I also need to on the Users Page, show the tags ("Running") from which to choose.
I need to let User select the tags, and then generate the recommendations of Sports based on the associated tags
I know this is a fairly complex question, but I believe is a fairly common/basic app to build.
Thanks!
You should check out Railscast episode #382 on tagging: it shows exactly what you need!
http://railscasts.com/episodes/382-tagging
I'm using an embedded relation to allow the user to edit/add books to a library and in the same form to add/remove n authors who wrote the book within the auto generated admin.
Here is my problem: An authors name is unique, so when I enter an author that already exists the sfValidatorDoctrineUnique produces the error.
An object with the same "name" already exist.
What I want to do is catch this error and tell the form not to try to add the exisiting author anew.
Do I use the event system for that, or modify the validators or how can I do that?
thank you very much
hoodie
PS:
after some searching I found something that might be a solution but I haven't made it work yet
http://symfonyguide.wordpress.com/2009/09/28/symfony-forms-saving-process/
I my opinion you should not to add new author if it already exists.
sfDoctrineActAsTaggablePlugin do the same way. It searches for an existing tags and merge them with current (added by user from form) tags.
But here is one issue: Two authors - Aleksander Pushkin and Alexander Pushkin, is it same authors for us, but different for machine.
I am wanting to create an application that can allow users to add products for sale.
I want to make it so that a user can add whatever type of product he/she likes and let them also create stored and searchable attributes for their products - alot like google base does.
Does anyone know of the best way to do this ie model it.
I don't really want a table for each category as this would be possibly 1000s of tables.
What is the best way to do this? has anyone got good / bad experiences of this?
Is there any plugins that does this?
Any help would be great
thanks
rick
It sounds like what you want is a tag system.
If you want something more flexible you might want to look at using a document store instead of a database, for example CouchDB.
If you don't want to keep this in a relational database I'd suggest creating a Model called "Descriptor" that would contain the ID of the item being added, the name of the attribute "Color" and the value "Red".
To help keeps things consistent you could also structure pre-set groups of descriptors (for cars: make, model, color) as well as provide auto-completes for the value entry text fields.