Nginx and apache are powerful and effective servers by nowadays. Apache currently reigns as the number 1 server for websites and since its public release in 2006. And nginx has taken the world by storm and is now the number 2 server for active sites.
The Reason Why I Use Nginx and Apache Together is
- nginx serves static files (images, css, html etc.) really fast and efficient and passes php and .htaccess requests to apache for processing.
- nginx needs the help of php-fpm or similar modules for dynamic content.
- apache is hard on server memory.
- apache serves php and .htaccess (most cms site like wordpress needs it for rewrite) and if you throw in a php opcode cache like zend opcache or xcache it should serve php even faster.
nginx + apache with php opcache = performance and server resource efficiency
So far so good, in the next article I will show you the configurations. That’s it!!! See ya!!! :)
Now, open your routes file and add the following line to your routes:
Great, now we need to add some code to the magazines controller. Add the following code to the magazines controller:
classMagazinesController<ApplicationControllerdefindex@magazines=Magazine.order("created_at DESC")enddefshow@magazine=Magazine.find(params[:id])enddefnew@magazine=Magazine.newenddefcreate@magazine=Magazine.new(magazine_params)firstname.lastname@example.org_tomagazines_path,notice:"The magazines has been successfully created."elserenderaction:"new"endenddefedit@magazine=Magazine.find(params[:id])enddefupdate@magazine=Magazine.find(params[:id])email@example.com_attributes(magazine_params)redirect_tomagazines_path,notice:"The magazine has been successfully updated."elserenderaction:"edit"endendprivatedefmagazine_paramsparams.require(:magazine).permit(:title,:body)endend
This code enables the ability to read, write, and update the magazines in our example. Now for the views, first lets create the index view:
<%= link_to "New Magazine", new_magazine_path %><% @magazines.each do |magazine| %> <h3><%=magazine.title.html_safe%></h3><p><%= magazine.body.html_safe %></p> <%=link_to"Edit Magazine",edit_magazine_path(magazine)%> <% if magazine != @magazines.last %><hr/> <% end %><% end %>
Now, lets create a partial to store the form. Create a file called app/views/_form.html.erb and add the code listed below:
<% if @magazine.errors.any?%> <ul><%= @magazine.errors.full_messages.each do |message| %> <li><%=message%></li><% end %> </ul><% end %><%= form_for @magazine do |f| %><div><%= f.label :title %> </div> <div> <%=f.text_field:title%> </div><div><%= f.label :body %> </div> <div> <%=f.cktext_area:body,rows:10%> </div><div><%=f.submit%> </div><% end %>
Now, lets create the new view. Create the app/views/magazines/new.html.erb file and add the code listed below:
<h3>NewMagazine</h3><%= render "form" %>
Now, if you visit the new magazines page on your development server you will see that CKEditor appears.
Next lets create the edit view. Create the app/views/magazines/edit.html.erb file and add the code listed below:
Now for something super amazing. Instead of running the gulp task explicitly, lets have gulp run our tasks when the files change.
First reorganize some of our tasks:
- Rename default task to css.
Next create our file watching task. Could you guess what?… there isn’t a plugin for this. It is just part of gulp.
We will create a gulp watch task to watch our contents folder and run our default task on file change.
I know what you are going to say: “Blah, blah, blah… there is a plugin.” and you are correct.