ruby on rails - create a simple html page - ruby-on-rails-3

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

Related

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

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.

Best way to write test cases for json views? (I.e., web services)

I have a Rails app which implements a web service. I'm not sure how to best write tests for it.
It has one controller. Each method provides json output. As far as I can tell, functional (views) tests would be the right thing to use, but they seem to only work with HTML.
i think that you could be good with using a library like json_spec.
in combination with cucumber this could also server as a documentation for your api-users. have a look at this nice blog post using json_spec.

Is support planned for embedded resources with ASP .NET 4.5 css and js bundling features?

I read Scott Gu's article about built-in support for bundling and minification in ASP .NET 4.5.
However there's no mention of embedded resources, which is a pity.
In the past I've been using a Codeplex project called Client Dependency Framework which supported embedded resources.
Seems like a pretty major omission to me. Is support planned?
I'm pretty sure you could write your own transformer to handle this.
Create a class that implements System.Web.Optimization.IBundleTransform.
Then in the Process method get the contents of the embedded resource. This shouldn't be too difficult. This blog post might be helpful.
Then add the transform to the bundle.
e.g.
var bundle = new Bundle("~/Test").Include("~/Content/Site.css");
bundle.Transforms.Add(new EmbeddedResourceTransformer());
Note that I am using the nuget package from System.Web.Optimization, not Microsoft.Web.Optimization (I have no idea why there are two different namespace implementations, and whether the syntax would be the same in both).
I also can't vouch for the performance of doing it this way as opposed to the file system.
Hope that helps!
Just a few comments on above answers since I don't have enough rep. to comment directly...
The answer from Hainesy suggests using a BundleTransform. I believe this is too late in the process to include an embedded resource. The BundleTransform is helpful for converting things inside the css or javascript after the contents are pulled from the original file and before they are put into the bundled file. For example, if you need to modify image URL's in CSS to point to local relative url for dev and to a CDN url for production.
The link from user960567 explains how to use embedded resources, but there's a catch. That process will only work for something like a common control used from another project.
e.g. If you create a textbox that needs CSS and JS then it allows you to create a HTML helper in the common project that will add the textbox and the script tags that pull in the embedded resource into the page. It does not allow you to pull the embedded resource from the common project into a bundle in another project. This will basically create a separate script or style tag for each embedded resource which may not be what you want (at least it's not what I was looking for.)
I've written a detailed article about how you can use the bundle and minification technology to wrap up your external resources here.

Writting My lightweight MVC framework

I have planned to write my own light weight MVC for PHP, that will be used as base for my sites I develop. I have no problem with PHP, OOP, et al. I have trouble on how to actually load Models In controllers and use them amd loading Controller values into Views. In short, I don't know how M-V-C interact behind the scenes.
Any tutorial (concentrating on that) or any contribution is welcomed!
Thanks!
ASP.NET MVC is open source: http://aspnet.codeplex.com/releases/view/58781
Edit: consider this: I believe you are trying to reinvent the wheel, thinking that those MVC framework out there are heavy and packed with uncessary features (acording to your double use of the word lightweigth). In my experience, I always ended up coding those extra "features" because a framework is required to evolve. Loading models In controllers, using them and loading controller values into views is just the begining. If you want to get started eventually, it would be a better investment to write some helper classes and methods: a popular pattern in the MVC world. Unless you are writing a MVC framework from scratch for fun and I am totally wrong (you said you needed a base to use for your sites ).
Best of luck!
Codeigniter is an open source MVC framework of php.
http://codeigniter.com/user_guide/overview/appflow.html
The major in MVC is first of all your controller class initiated and then calls view.
After google and check how other MVC works I decided to take this route. I redirect all my requests with .htaccess to index.php. Then there I define base paths. After all the definitions I include the core.php which in turn includes all core files to my mvc framework. Then in the same file I create Instances of Registry and router and the game starts from here!
Internals are a bit complex now but that is what I ended with!

Web application programming using objective-c?

Just say you have a quite large and complicated desktop application written in objective-c/cocoa written properly in MVC. You then wish to replace the V and C so that it is a web application?
Is there anything like Tomcat but for objective c? The closest thing I can think of is somehow convert the Model code into an apache module to load in apache?
Obviously I could embed some sort of HTTP server and write a whole pile of code to manage sessions and requests and responses and so on, but might there be a simpler way?
You can leave the server almost as-is. I'd run it as a daemon in the background.
I'd split the controller part. One part of it resides on the server as a connection between HTTP requests and the daemon.
You could run a self-made http server.
You could build it into a Apache module as you mentioned.
You could access your controller through CGI. This is the easiest option as I see it.
The second part of the controller is written in Javascript in the browser, exchanging data with the server and updating the GUI.
The view part is written completely in javascript.
You could - if you want - leave out the controller on the server and make the model understand HTTP requests.
For the Controller / View part consider using a framework.
jQuery for only a light interface. (Or a similar framework.)
I haven't yet found a framework that leaves all the model stuff to the server. Maybe you can use SproutCore or Cappuccino accordingly.
SproutCore, the full-backed MVC framework that is used by Apple. (Think so at least.)
Cappuccino, another full-backed MVC framework.
Have you looked at Cappuccino? http://cappuccino.org/
I have not used but have heard many good things about it.
There is a new web development platform for Objective-C/Cocoa called Bombax. It sounds like exactly what you're looking for (it is designed to allow you to write entire web applications in Objective-C). Perhaps you could even combine it with Cappuccino. You can check it out at http://www.bombaxtic.com.
The closest you'll probably come to Objective-C web frameworks are either SOPE, or GNUStep, neither of which I have used, but ran across when I was deciding if I wanted to use Rails or something written in Objective-C for my web stuff. There's also ARJDatabase, which is kind of like Core Data, but not source compatible.
The bottom line is, unless you were very careful about how you wrote your code (i.e. wrote it with GNUStep in mind, didn't use anything Apple specific) you're probably going to have to do quite a bit of work anyway. And if you used Core Data at all, there's no way I know of to reuse that outside of a Mac App. And since it's not setup to be used my multiple simultaneous users, you wouldn't want to use that in a web app anyway. Bottom line, I went with Rails.
There is Frothkit - http://code.google.com/p/frothkit/ but it appears not to have been updated for a year.