I've got a use case where I'd like to POST some data to my Volt app, but there doesn't seem to be an obvious way to do it. app/main/config/routes.rb doesn't recognize a post method like a Sinatra route.
I also tried a Volt-external class tied into the app via config.ru, and I can POST my data to the same Mongo collection that Volt is using. But that data is not reflected in the app until I refresh the page, which is less than ideal. I was hoping my reactive models would see the change in the DB and reflect that on the front end.
I understand that Volt is in beta, so this feature may not be implemented yet (or even planned for the future). Is it possible to do this?
Long term I'm going to make it so you can route REST requests to Tasks (or possibly another set of classes). In the short term, using rack is the right way. I'm in the process of adding a wrapper to the mongo api that knows how to trigger the updates. Should be out in a day or two, I'll update here when it is.
Related
I'm looking at frameworks and CMSs for a project we are starting, a website that needs to support localised content.
Laravel looks good and certainly allows you to localise UI content, but it doesn't seem to natively support the localisation of content stored in a database. This seems surprising, I'm wondering if I'm overlooking something? (CakePHP, for example, has a TranslateBehavior for this purpose).
Edit To be clear, I'm asking if there's anything baked into Laravel to handle this, I'm aware I could code equivalent functionality but think that that would be a fair amount of extra work.
Modifying your data as it enters or leaves the database is fairly easy.
If you store the translation key in the database, you can translate when you pull the data out. Use getter and setter methods in the model. You may also want to look at Model Events.
im trying to create a Single Page Website with DurandalJS in the frontend and Laravel as the Backend. Do you think this is a good Idea?
If yes how would I do the following:
What would your recommendation for the basic interaction between both frameworks be?
Would you rather have all the computation done in JS instead of Laravel sending calculated and styled returns?
How Do I setup Laravels controller in order to only get dynamic Data for, say a Div, instead of a whole page?
How can I adjust the browser URLs?
I hope I was specific enough, thank You in advance.
Laravel does not actually care about what framework you use to build the Frontend. Laravel is just a framework that helps you build your application with. It gives you great advantage with respect to the time spent and effort.
You can use any frontend framework that you want to build your app with. I have actually not used Durandal, but from the first look of it here is my opinion.
Durandal is built on top of jQuery, knockoutJS and requireJS. It also has a MV* architecture in place with support for eventing as well. So you could basically define routes on Laravel and initiate the communication between both the frameworks through events and ajax. Again this completely depends on the functionality that you are building.
In the overall flow of your app, consider Laravel as a Model that just gives data from a source to your app and Durandal as your views and controllers. This way, it will keep your data flow cleaner and easier to build. Computation of your functionality depends on how important and secretive the app is. If there are functionalities/implementations that you need to be secretive about, you can keep it on Laravel and just send computed data to Durandal. If its a web app that you are building, then keeping all implementation on the JS is just a right click away from knowing what and how you have built it. One can just see how the implementation is done just looking at the Javascript source of the web app. If you are building Mobile Device App, then the case is different.
Take a look at Restful Controllers. Will give you an idea on how to setup controllers to return only data. But if you need to return the div itself, then you can make use of the Basic Controllers of Laravel to perform them.
You can setup cleaner routes for the browser URL's. Take a look at Laravel Routing
I am having a rails app that basically changes replaces images at pre-decided time. Now i want to create a ruby timer that triggers an event every second and when any image time is reached, it throws the event and the image changes in the view. I was thinking of using observer pattern for this. Can anyone please advise me on how to go about doing this?
Any help is appreciated.
Have a look at gems that handle scheduled tasks for you. I've used Taskit quite successfully in the past.
http://ruby-toolbox.com/categories/scheduling.html
Sounds like you may also want image-rotating Javascript...
RubyOnRails is a server-side technology. It does not work in the way, which would let the rails application to change the 'view', after it has been rendered and sent to the client's browser.
You should use a JavaScript for this task.
You may decide who (client or the server) decides which image to serve. You may place all the URLs of the images in JavaScript, or you may provide a single resource in your rails application, which will return different images (or their URLs) in each request. There are many ways, but if I understood your question correctly, observers are not related to the problem.
I want to spec a Sinatra server that receives HTTP requests, stores things in MongoDB, and responds with JSON. How would I spec both the MongoDB entries and the responses?
I'd like to use Cucmber and RSpec to do this cause I hear they're hot, but I'm not really good with them yet.
My learning so far with BDD is that you need to think in very small steps. E.g. you could start in making specifications with rspec for your routes, example project with sinatra here, and another example, here.
Then you could start in making specifications for your model layer. Small steps also here, check for validations, setting and getting attributes.
Last, you might approach to specify the view, here you need to learn about mocks and stubs for your controller and models.
Cucumber is a different story in my view. You need to write cucumber specifications when you work with your customer, to understand together the requirements of your app. It facilitates acceptances testing as far as I can see.
I'm trying to get my head around Cappuccino. I'd like my StackOverview peers to review the architecture below and see if it makes sense - the aim is to utilize the unique benefits of Django and Cappuccino without doubling up where the technologies overlap...
When the web browser requests a 'friendly' URL (eg, /, /articles, etc):
DJango's urls.py matches this to a
view.
The view, rather than doing
DJangos typical work of filling in a
template with the locals dict,
returns the small 'stub' HTML used in
a Cappuccino app directly.
The client receives the Cappuccino HTML
The client requests the Objective J JS
URLs mentioned in the stub HTML
The end-user app is executed and
displayed in the browser
The browser now has a working app. When the user does something that
requests something from the server:
The browser sends an XMLHTTPRequest to a URL.
Django's URLs.py matches this to a
view.
The view does it work, perhaps interacting with the DB model. But instead of returning a template, Django returns some JSON.
The client recieves the JSON, and
does whatever it needs to do.
Does this make sense? We still have the benefit of friendly URLs, and the database being created for us to model our code. However rather than using templates, we're providing Cappuccino stub pages and JSON responses, in order to give users something more like a real app and less like an HTML templating engine.
Is there perhaps a better way of doing things? What do other Pythonistas use? Thanks for your feedback.
For a low traffic site, using Django's routing layer would be fine, but if you plan on getting a significant amount of traffic, you might consider having your proxying webserver handle the stubs.
As for the rest, it works and the TurboGears community has been doing it for years (I was a TG committer so that's what I normally use). The TG architecture of returning a dictionary to a template makes this trivial since you just set 'json' as your template engine.
Doing the same thing in Django isn't much more complicated. Just use the serialization tools to write the result to the response rather than using the templating calls.
Note that when you do an architecture like this, it's considerably easier to manage if you keep all the application logic in one place. Putting some app logic in Django and some in the browser causes things to start getting messy fairly quickly. If you treat your server as a dumb persistence layer (with the exception of validation/authentication/authorization), life is easier.
FWIW, I find Sproutcore to be easier to work with than Cappuccino if you're interested in heavier non-progressive enhancement frameworks.