I would like to create a blog with an Ember front-end, a Rails API acting as the back-end and and AWS to store the images. I was thinking of dividing up the posts into objects: paragraph, image, etc... and storing them in a relational database (postgres). This would then allow me to generate the corresponding Ember components on the front-end depending on the model i.e. render a paragraph component for each paragraph, an image component for each image, etc. I figured this would allow me greater flexibility when displaying the posts The end goal would be to also create the CMS to manage the blog. Is this the right way to go about this?
Is this the right way to go about this?
Your approach is good. A solution should depend on flexibility need when it comes to displaying, manipulating these paragraphs, images etc. If only CSS styling isn't sufficient then sure, you can go with storing each paragraph, image as a separate entity in the database. It should be very easy on Ember side to work with such API.
You can do as you said : a document is a set/group of entities (images, paragraph,...) or you can keep it simple : store the content of the blog post in a specific syntax (example: markdown) and when display you can prefix image to AWS.
For sure the more, you divide the more you are flexible, but you will need to have more relation between entities
Related
I'm wondering what the best design for the following would look like in Rails:
A website with three different image galleries, let's say one showing pictures of the company's staff under mywebsite.com/gallery, another one shows pictures of product A at mywebsite.com/productA and the third shows product B under mywebsite.com/productB.
I assume it would be bad design to create a gallery resource, along with a productA and a productB resource since there will be only one of each and it's really the new photos and not new image collections which will have to be created.
So I'm thinking if it's a good idea to create an images resource and then use single table inheritance, instantiate a gallery_images, productA_images and productB_images and change the routes to the respective ones which I want to show up as URLs. I should probably mention that I don't want to mix up the images for the different sections.
I feel there must be a "proper" way of doing this, I guess tons of websites use a similar scheme.
Not to say that this is a "Rails way", but I've seen it done as follows in most of the Rails projects I had access to. Basically, when it comes to galleries, you would want to let customer upload and manage the images. So, you would use gems like paperclip and carrierwave. Once you choose one of these gems, your class design is predefined. You'd have a model that has an attachment.
Then, you would simply initialize a specific instance of your model (or a model with has-many attachment model association) and simply render a list of image URLs in your HTML template. The actual gallery is then styled and brought to live on frontend using CSS and JS.
As for the difference between other contexts. Let's say OOP. If you are looking for the "correct" way of doing it in OOP context, you would first have to consider your business domain. And design your classes so that they reflect your business requirements (taking into account all OOP principles). A best way to start this journey would possibly be learning and understanding OOP principles and forgetting that "Circle extends Shape, Rectangle extends Shape and this is what OOP is!" kind of mentality. Design patterns are actually a good example of what you end up with if you follow OOP principles. Head First DP is a good introductory book.
I think it would be good to incorporate tags/tokens with an autocomplete feature. I will use Wikipedia article titles to dynamically build the list of possible tokens (thus enabling autocomplete.) I am using Rails 4 and Ruby but any pointers would be great, I don't quite know where to begin with this.
The purpose is so that users do not just make up anything as tag (tagging themselves as expletives+nouns, for example.) And if it became possible to keep this master list updated (which is what I meant as "dynamically", it would be great. But even manually updated is ok.
I so far assume that part of it would include a web crawler that only searches :title fields on wikipedia. I am using Postgres as my DB.
Once I have a list, I can use something like the jquery token fields gem or chosen gem, as I learned from Railscasts. In those two examples, there was a list that enabled the autocomplete for tokens. I want that exact thing, but to get them from Wikipedia titles.
http://railscasts.com/episodes/258-token-fields-revised
This will be done in Rails 4 and I am using Postgres. I will probably be on Heroku as well.
You could use the API to fetch titles beginning with whatever the user typed so far like this: api.php?action=query&list=allpages&apfrom=Bav&aplimit=5 (assuming english Wikipedia here). Add &format=json or &format=xml.
Many of the suggestions, however, would be quite meaningless in other contexts than Wikipedia, e.g. titles with disambiguation suffixes: Bac. And most of the expletives and nouns you can think of will be there, so it won't do a good job at sorting them out, either.
If you plan to use the function on a heavily visited site, you should probably download and host the list of titles yourself, not to put extra load on the Wikimedia servers.
I'm developing a site with Ruby on Rails. I have data on layout that doesn't repeat more then once. And I need to enable content-menegers to change it easily. I could create a model or several models for them and let content-managers edit it in RailsAdmin. But I doubt I should use models that way because entities of such models will be ment to exist in singular number. I mean there aren't multple site names, logos, backgrounds, welcoming texts, etc. But I want to enable them to be edited in a web-interface or equally comfortable not worrying about the cache and not looking at code and serfing through complicated directories structure.
What is the right way to do that?
I am developing my first Rails app, a web replacement to a paper form system. Some way through development I discover my client wants to be able to add ad hoc new forms to the live system.
I have considered using wufoo/ google forms/ or survey monkey, but I don't think they are going to fit the bill, due to integration requirements.
What I basically want is to enable one or two super-users to create forms, which will then be available to other users in the system. When the forms are completed the output should be made available to my system. The data is to be manually collated for analysis, so even CSV is fine - there is no need for complex modelling.
I have been struggling to find any paths to a solution - I really don't want to build a form builder myself! So if anybody can point me in the right direction it would be most appreciated!
Cheers!
The liquid template is a good choice for custom building web pages. The easier approach is creating pure HTML pages with form to your system, if your customer allows to.
For the data storage, you'd better try nosql database, such as the mongodb and mongo gem as the ruby adapter, so you can save any data structure without managing the tables and columns. By the way, you have to learn some ruby meta-programming skills to process the dynamic data from the client.
I'm currently building a web app (atop Ruby on Rails), which will let users style their own areas (personal blog pages), and was wondering what are the best ways of accomplishing this?
I think Liquid for templating would be good, but how would you handle styling? My aim was to have a DB field associated with each blog dubbed "style" which will store a custom stylesheet, is this the best approach?
I've tried it so far with the "sanitize_css" helper method, but it just strips the "#stylebox" tags out, meaning nothing is displayed.
Any ideas?
Thanks.
Currently I'm also working on almost a similar requirement as you do. I'm also trying to create a CMS for users to add pages, style them etc..
My Approach as follows
each user will have his/her subdomain. (I use a before_filter to get the current users subdomain and load his/her website)
About styling, I prefer to have the style sheet as a physical file. Given that your method will have the more flexibility of editing the style sheet, I dont like the idea of having the stlesheet code on top of my page. Insted, I allow users to load their styleshets (Using paper clip)
So when the site loads I will get the css paths from the DB and load the stylesheet from the path.
Later I'm planning to read the file and load it to a textarea so that users can edit their stylesheets and when saving override the existing file;
For layouts i use liquid as well
cheers
sameera
I would honestly allow themable elements on your page, and then store each of those style rules as a field (or conglomerate them into one giant field) in the database. Enforce some validation to ensure that they don't use any funny business (if they're only coding for specific div's, they shouldn't need to use any curly braces.)
Then generate the CSS on the fly.
The reason? If you ever want to serve up ad's on your site, and you allow them to just upload the entirety of their CSS, they can easily turn off visibility on the ad div.
I think it's "safer" to control what they're allowed to theme; sure more advanced users will get ticked. But do you really want to be the next MySpace? ;-)
if there is too much of code then serialize the data and store it as text in db.
That would be much better i think
If your going to allow areas for users to have complete control over their CSS, then I would probably avoid the database altogether and use a structured file system approach. You could create a sub-domain or folder for each user that contains a main.css. This also allows you to scale well as features grow for your user (pictures, etc.)
With that said, as Robbie mentioned, you might want to consider limiting what styles a user can and can not control. Otherwise, you would probably find things getting out of hand quickly. For this approach, you would probably want to use the database for storing property values of the elements that can be modified.