Ruby on Rails - using a Themeforest Admin Theme with my project - ruby-on-rails-3

I am trying to build a CRM tool for a particular niche. I'm a complete newbie. This will be my first app. My only programming experience is with VB and MS Access, so RoR is presenting quite the learning curve. I have worked through the first version of Michael Hartl's Rails Tutorial. (And actually absorbed about 10% of it)
I bought a Themeforest bootstrap admin theme and have two general questions on it:
1) The theme has some PHP code in it. I'm assuming that I should re-write this code in Ruby, right? The code mostly controls things like file uploading, etc.--things that could be re-written in Ruby by an experienced programmer rather quickly (for me, it will take months :)
2) The theme contains a number of different pages. For example, one page is a dashboard, and another is a calendar. Both of these pages have a lot of duplication between them - all the main control buttons, etc., stay the same from page to page. In the theme, each page is a different HTML file where all of the code is simply duplicated. I'm assuming that I'll want to set up some sort of template system in Rails so that I don't cut-and-paste code between a bunch of HTML pages, right? (If I change a main button, I only want to make that change in one place, rather than in each of the 20 HTML files that came with this theme.)

1)
I'm not absolutely sure if there's no other way, but it's most likely the easiest solution.
If you have to rewrite stuff that's common in web apps, like file uploading, there is usually a gem to help you out, so you don't have to do everything from scratch. I can recommend the paperclip gem, Railscast for file uploading, since we use that in our own project.
Note: The Railscast is out of date, so the installation stuff is no longer accurate. Also, paperclip requires ImageMagick to work.
Railscasts also cover lots of other useful gems. If you need to find something specific, just google it. The github page then usually reveals if a gem is still maintained or if you're better off with something else.
2)
Rails prevents duplicated code with partials. Here's the Railscast (syntax might have changed since 2008). Partials let you place code like headers, or buttons in your case, in a file, which can then be rendered in any of your views.
Unfortunately, I can't link the other stuff like the github page and Rubygems.org because I lack the reputation. I hope this still helps a bit.

Extract the common elements of the theme into your application layout.
Extract the modular sections of the theme into their own controllers and actions. For example, create a calendar controller for the calendar section, the actions that appear in the calendar controller will be the views that support the calendar. You can also use partials (views that start with '_'), without having to create a controller action. But if there is data that needs to be sent to the view, it is better to stick with normal controller actions and views.
As for the php code, get rid of it, move as much logic as possible into your model and controllers, with preference to putting in your models. As hobo suggested, check out gems to replicate the functionality of any complicated php code.

Related

Better style inside a vue.js app or outsource to the site embedding it?

I'm building my first vue.js app and I'd like to have some help on deciding a design approach.
This app is going to be embedded inside a page of a site - built with Drupal 8.
Both app and site are going to use bootstrap 4 as base framework and we're going to use sass to style.
It's a quite simple app: a multistep form with some ajax call done to the aforementioned site.
It has anyway some components - one for each step, for some of the more complex input, for a sidebar showing the result of the ajax calls and so on.
I need to decide the "guideline" for styling this app and I'd like to get some help\insight to what solution is better.
On one hand, I could put the style inside the app itself; on the other hand I could leave all the style to the one present on the site.
As far as I can see the benefits of the first approach are the use of scope of each module, thus having a better "modularity".
However, putting the style all inside the site would avoid code duplication - simple example: custom color variables.
Personally I can't see for now other differences right now.
I haven't found material about the suggested approach and the pros\cons.
Could advice me of which approach is the best? Thank you.
It depends on the project, but you can make a list of cons and pros based on your project brief. If there are very few (or 0) changes in the future or it's based only on small components (not much style) then go with component-scoped styling. If the project is big, always go with a style pattern like the 7-1 pattern
I prefer working with the 7-1 pattern pattern.
Pros:
- Scalability or future updates like you mentioned the color variables case.
- You don't depend on Javascript to load the style, depending on how you write the app or how it loads, it may have glitches.

Sitefinity 4+ -- Standardizing intra-site modules in Sitefinity 4-5.x

We write a lot of intrasite modules and are noticing that they really deviate now in SF 4+ from the content-based ones. So, on that note, I have some questions:
How do you get the EXACT look and feel of the standard modules for the edit/create form? For example, how do you eliminate the menu above, center the form, etc, as in, say, the Events module?
How do you add an actions menu dropdown to a radgrid, same as you'd see in the grids for standard modules?
How do you incorporate Sitefinity fields into the usercontrols? For example sf:ImageField throws script errors when added to a control? Also, is there documentation on each of these fields and how to configure?
---finally---
If we really want that standardization, do we have to go with another module type?
4.Is there a module type that will allow us to access non-sitefinity data (ie separaate db
but also provide us with exactly the same functionality and UI experience as the content-
based modules?
intra site modules are simply custom user controls (ascx) placed into backend pages to add your custom functionality to the backend. To copy the look and feel of the rest of the site, I literally copy and paste the HTML into the control.
I did a webinar on this a while back, including code to recreate the backend editor. It appears to still be valid, and is available here: http://www.sitefinity.com/blogs/joshmorales/posts/josh-morales-blog/2011/06/30/sitefinity_intra-site_module_webinar_notes
the centered view is a bit different, and I don't have that html, but you could potentially do the same (copy it from another native page). I don't always get it 100% accurate (my controls are usually laid out different from what Sitefinity does) but I get close enough so that it doesn't break the user experience.
The actions menu could be recreated with javascript, but if you are looking for NATIVE integration that does all this for you, indeed you would be looking at inheriting or much better yet: simply using the module builder, which lets you build custom types that automatically install themselves into Sitefinity as if they were regular modules.
Fields are definitely designed to run inside the context of native sitefinity module definitions (the classes that make up the UI using the Sitefinity context). This doesn't mean you can't include Sitefinity content in your modules; it simply means if you do you'll have to implement the integration yourself using the API.
On your last question, the only way to use external data but still keep the "Sitefinity Content" UI is to inherit from Content, then create a custom provider that reads from your database and translates it into the Sitefinity content type. It is certainly possible, but is quite a big project.
Unless you are in full need of this tight integration, I recommend simply going intra-site, linking to Sitefinity content types,taxonomy, etc through the API and manage it separately.
I hope this was helpful!

ruby on rails - create a simple html page

I need some assistance in creating a simple html page and locate it in the server.
Since I couldnt find it in the doc I tried to put a index2.html file in the /public library and when I tried to get receive it using
http://127.0.0.1:3000/index2.html
or
http://127.0.0.1:3000/public/index2.html
and receiver
ActionController::RoutingError (No route matches [GET] "/public/index2.html"):
how do I get the html from the server
how di I make it the default.
Thanks.
EDIT : thanks for your answers. I am looking for the simplest way to work. in many tutorials it says you can put it in the public folder and thats it. This will same me useless controllers.
You can do that in several ways : the more obvious would be to have an action in one of your controller (or a new one, whatever) that does nothing (except render the view), and add a route to it. There is other ways to achieve this too, with more adapted tools. I never used any of them, so might want to google it (static page rails), but I know one of them is a gem called High Voltage. Hope this serves you well.
I think you might have mis-understood Rails...
I have never used it but I think I can probably help you with your answer. Rails is the most popular MVC framework for the language Ruby, hence 'Ruby on Rails'. Here is a link to the MVC framework this may help you understand it:
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
With the MVC framework you can't 'get' a file directly through the URL. You have to get it through the routing engine. Usually you do this through a Controller which renders a view, typically, from a model.
It's difficult to explain if you don't understand how the MVC framework works but once you have an understanding you should be able to develop web applications very rapidly.
Have a look here for creating your first rails app:
http://guides.rubyonrails.org/getting_started.html

Automatic website creation using rails

I am looking for a template generator for rails, much like the scaffolding, but complete with preset pages and css, everything already built-in generically.
I am unsure where or how to search for this.
The reason I want something like that and not create one myself, is that I need to create a website really quickly with a certain preset theme
I had the same problem that you had, and could not find a solution. Therefore I built a gem for it.
https://github.com/bighostkim/simple-layout
It only applies to your development mode and it does not use asset to make it simple.
Hope it helps.
Rails Yard may be the solution you are looking for. It is a CMS written in Rails.
Rails CMS WIKI FORUM 2nd option
Rails Admin is great for data management (Create, Retrieve, Update, Delete).

Dynamic web page convertible to PDF

I'm thinking about writing a professional CV page that would be easy to update, using a simple backend to add informations and blocks of optional details, and... (feature creap coming)
Anyway, I was thinking of a "simple" web page grpahically, that would easily be convertible to PDF file, using browser functionallity or not.
Assuming that the page have blocks of text that you must ckick a button to see (those are optional details), what should I know or what tools should I use to write this web page?
I'm totally rusted on web code, I used php without ajax a lot before but I understand the idea. I was thinking maybe it would be a good opportunity to try a framework to make a "webapp", like Ruby+ROR or Python+Django? Is that a good idea? I'm ready to learn about those, I'm just not sure if it's worth for such project.
Should I know some things about html code or javascript behaviour that I shouldn't use because it would break any PDF generation tool or something like that?
Any advice on the way to proceed would be helpful.
You'll want to read up on how to create a print stylesheet. This way when you go to print the CV you can choose something like CutePDF Writer and your print stylesheet will automatically be used. You will make your stylesheet show all hidden text blocks and hide things like navigation, buttons, etc.
I can't tell you whether or not it's worth it for you to try a new framework for this project, that's up to you. It's not bad to learn new things. Since I don't know all the details of your project it's hard to answer if it's worth it for this particular project. From your description is sounds like you're just making an HTML resume/CV which sound, to me, like one flat HTML page with some JavaScript. If that's the case you could probably just use a text editor.
If you want my personal opinion, ASP.Net 4 is the way to go if you want to learn something new (or if you just want to use a great framework).
As far as breaking the PDF generation, your print stylesheet will be responsible for showing/hiding things but any JavaScripts should be aware of this as well. Check the link I gave you above for more information.