Rails, Where should view specific constants be placed? - ruby-on-rails

I have view where I show information through several panels, one panel for each category.
I would like to have the list of panels-to-show in a constant/variable/container which the view can access and show only those panels.
(At least so far) This list of panels is specific to this view.
What is the right place to store such view specific configuration?
Some choices I can think of are
(i) variables in the controller action (related to that view)
(ii) in the view helper method
(iii) in the view itself
Thanks,
Kumar

Create a file in config/initializers/constant.rb
Put your all CONSTANT here

When I create a website with configuration like you're looking for, I use a Configuration Store.
Try / Take a look at the following gem : https://github.com/chatgris/Gaston

Related

End user can edit the view of a recored in some sort of editor - rails

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.

Where should I put data like testimonials and addresses in Umbraco?

I am fairly new to Umbraco and I am wondering where I should put pieces of random data.
I have a lot of experience with Sitecore, used it for several years, I am certified etc etc. But now I have to build something with Umbraco. At a first glance Umbraco looks inferior to Sitecore in every way, but I might be wrong about that.
So what I am wondering is, where should I put non-browsable pieces of data that are visible on several places throughout the website? I'd like to create data items in Umbraco for things like Testimonials, Offices? I'd like to have a centralized place in Umbraco where they can be maintained and reference them from a page node. But the way it looks now is that everything has to be on the page node. Which is sort ok, for your average family webpage.
Could someone please shed some light on this?
You could create another node under the man content and call it site settings and store them there that way all pages under the home page are just visible pages on the front end and all data nodes are in a separate area.
There is one property in umbraco that you can add to document types and name it "umbracoNaviHide" (for alias, the name can be anything). This allows wires in automatically to the .IsVisible() method.
var children = Model.Content.Children.Where(x => x.IsVisible());
I find this situation to be very frequent, think of slideshows. When I make an Umbraco website, under my root node I normalle havea Slideshow document type (that contains slides) and I programmatically traverse those to build the slideshow on the home page for example. This Slideshow document has that "umbracoNaviHide" property and I skip it from my menus either using the .IsVisible() method or by manually skipping specific document types.
var menuItems = Model.Content.Children.Where(x => x.DocumentTypeAlias != "Slideshow" && x.DocumentTypeAlias != "Search");
On the other hand, if you are looking for "labels", you can look at "Dictionnary" items under the "Settings" tab.
To directly answer your questions, I reccomend putting non-browsable pieces of data as children of the relevant browsable content node. (But there are other valid ways to do this, it really is up to you and what's best for your content editors.)
Hope this helps.

Ruby on Rails initial controller setup

I'm getting started with Ruby on Rails and have some questions. I currently have a website that is written in Perl/HTML/Javascript, etc. My goal is to convert this website to use Rails. I'm running into a stubmling block on how to get started.
Here is the general overview of the current website:
The main page has 3 selection lists that get populated on page load (via SQL). The user can select an option from one of these lists (say a date as one of the lists stores dates). Currently, using AJAX, this calls a Perl CGI script which queries the database with the chosen date and returns a table containing the appropriate records (fills in division next to the selection lists).
There are no other pages on the website (besides a changelog) as everything happens on the main page. The selection lists do not get refreshed after each selection due to AJAX.
My question is, would I have a controller called Selection to populate the lists and another called Output to create the table of records? Does that setup makes sense?
Thank you!
This is my understanding about your requirement.
1) You have a page where there are three selection boxes
2) If a user changes any one of the selection box, then you are posting data to backend to get output based on the selection (using Perl CGI script)
The output is loaded after you get response from backend.
If my understanding is right, below are my suggestion.
Suggestion :
You need not to have different controllers for each action, in Rails you may have multiple action within a single controller.
Say you can name your controller and action as below
Selection Controller (Can have multiple actions under it as below, you can define custom names for each action in controller and add routing information in app/config/routes.rb file)
- GenerateList
- CustomAction1
- CustomAction etc.,
EDIT :
You should not use single controller for all your actions in the website, you need to categorize
functionality and create multiple controller/actions accordingly.
Let me know if you face any difficulty in creating and running custom actions.

How to handle front-end content in order to display menu items based on the current user?

I am using Ruby on Rails 3.2.2 and I would like to "handle" / "generate" the proper front-end content so to follow a "common" way of managing menu items mostly based on the current user "equality". That is, I would like to display different menu items based on
the current browsed page;
the current user that is accessing that page (the page could be related to a user that is not the current user).
Where (for example, in controller, view or model files) and how (for example, stating checks related to the current user in controller, view or model files) I should "state" / "put" those "conditional statements"?
At this time I think (mostly for matters relating to the current browsed page) I could handle this matter directly in controllers by using helper methods...
I tend to put this into the View files with simple or static cases coded into the View file and more complex cases which would require more than just one line of coding into the helpers.
But in order not to bloat the view file, I suggest to use partials to offload blocks of code from the view file.
One of the reasons why I use the views is that I will do certain user based formatting anyways, e.g. if I list all the orders, then the normal user will see certain columns displayed, whereas if the admin logs in, he will see a couple of additional columns. This is typically done with something like
<%if #curreny_user_type == 'admin'%><td> ...... </td><%end%>
Thus before I now start splitting up some of the user based logic into the controller and others into the views, I'ld rather have them always at the same place.

Expression Engine Channels, Categories and Entries - All with differeny custom fields

I have a site with these sections in the top nav:
About Us
News
Staff
Become a Member
Within each top nav item, is X amount of sub sections. eg:
About Us
Who We Are
Industry Stats
Annual Report
Then, within each one of those has X amount of sub pages:
About Us
Who We Are
Overview
Our History
Our Objectives
The root level top nav items (About Us) will always require the same custom fields.
The middle and bottom level pages will generally have the same content, and but will be much different to that of the root level, and so requires a different set of custom fields.
I have set the structure up so that the root items are the channels, the middle are categories, and the lower levels are just 'entries'.
My problem now, is that using a 'channel field group' on the root channel obviously filters through all categories and entries associated. So when I go to edit or publish a category landing or entry page - i am stuck by being shown the custom field group for the root landing page.
I would like it so that the end user (my client) doesnt have to see a lot of custom fields when they edit or publish a page that isnt at root channel level.
How to I set this site up, so that I can pick and choose different field groups on different pages that are within the same channel?
While you can use custom Publish Page Layouts per channel and per member group, as far I'm aware you can't present 'pages' or entries with varying Publish Layouts.
If you're using different templates for levels in your navigation, Blueprints, may be what you're looking for.
Blueprints lets you take control of your Publish Layouts [...] It is designed let you create Publish Layouts based on templates.
The taxonomy in how way you've architected your navigation and 'pages' is interesting, but not one as a client I would like to maintain or understand. For example, something as simple adding a new top-level section or page of the site should be easy, but with your methodology would require setting up an entirely new channel!
Some ExpressionEngine add-ons that may be better suited for your site and still allow you to achieve the customization you desire would be Structure, NavEE or Taxonomy — of course theres always the the native Pages Module as well.

Resources