I've just finished going through my first book learning RoR and wanted to practice some more extending the project, but I'm at a bit of a loss for how to structure the additions I want to make and would appreciate some guidance.
Right now the application is separated by pages that have a model controlling the logic and a controller routing that logic to the view, but none of the pages have any cross-over in features. I want to create a page that has pre-templated features with logic from other models, sort of like widgets in WordPress, or plugins in Magento. If I had a Page model and wanted to inject a Bestsellers list in the view, or I had a Blog model and wanted to inject a list of products with a tag calling out to a template with all the markup already, what is the proper way to do this?
Would these have to be modules? Would I just create another view template for Catalog that I would call into the Page index view?
Nevermind, I found the answer to what I was looking for here
Related
I'm using Orchard CMS and want to be able to show sharing links (think AddThis.com or Shareaholic.com) to blog posts on a website.
Before I start I realise there is a similar modules already present in the Orchard gallery but a, I couldn't get the module to work and b, I'd like to further my understanding of Orchard.
My thought originally was simply to add a new blog widget layer and to add a new HTML widget that contains the aforementioned sharing code. Trouble with this approach was;
The layer rule would force all of my blog pages to have to be under some common url i.e. using a layer rule of something like the following. Not necessarily a bad thing but something that could be missed when the client publishes a new post.
url("~/blog*")
The sharing code contains empty html anchor elements that were getting stripped from the html when I saved in the Orchard editor.
I think #2 is down to the template used in my theme. I read a post from Bertrand Le Roy's blog about overriding templates which got me thinking. Can I just override the Orchard blog template and place the sharing code in there directly? Clearly this is less customisable in the future but I'm happy with that. I'm also thinking having fewer layers, moduels, widgets or whatever can't be a bad thing when considering Orchard performance and load times. I'd also now have my sharing icons on every blog post wherever it may be on the site.
Question is what is the view that I should override in this case? I tried editing the blog views in Modules\Orchard.Blogs\Views expecting to see some changes but I got nothing.
What would people suggest as the best way forward?
The best approach IMHO is to add the code in one of two (or both) templates:
Content-BlogPost.Summary.cshtml when the blog post is shown in a list (you can copy the code from /Core/Contents/Views/Content.Summary.cshtml) and
Content-BlogPost.Detail.cshtml when the blog post is shown in a separate page (you can copy the code from /Core/Contents/Views/Content.cshtml)
I am a little ashamed for asking so many questions, but I really want to learn.
In Sipke's blog a webshop is created. There is one specific question that boggles my mind when trying to do something similar.
Let me spell out the basic requirements:
User registration form and login, etc. This one is covered by the blog and it works nice.
Creating product parts and so on. This one is covered and no problem there.
Ordering by filling in an order form and making the payment. See down
Having the order page maintainable by customer. See down.
Viewing your own orders and their status. See down
Maintaining customers and orders from backend system. This one is covered by the blog and I need to do some work there yet.
As for items regarding creating orders and viewing your orders. I have followed the approach for creating records and using standard MVC controllers. But then I encountered problems:
Menu for orders page. This I had to do manually after installing the module.
The order page itself. I had to create the view including title and so on. But I can imagine a customer wanting the order page on another menu and with a different title. And maybe add even some own content to the ordering page. This I couldn't achieve by using standard MVC approach. So maybe I am using the wrong approach here. So I was thinking about using contentparts for creating an order and displaying them and using the drivers and handlers for that. But before I go down that road and refactor everything I want to know if that is the right approach. A downside could be that once the module follows that route it can then not so easily be reused with customers that have other cms's capable of hosting an MVC3 module.
So when to use drivers, handlers and contentparts and when to use standard controllers and views.
You should use Drivers and Parts (with Handlers if needed) when you want to create functionality for content items. E.g. if you want to display a custom media with all products, you could create a Part (together with its Driver, etc.) to handle that. Read the docs on Parts.
If the functionality is not tied to content items the most possibly you want to use the standard MVC toolbox, it's fine. Look at the built-in modules how they do that. E.g. the Blog module uses controllers and views to show the admin UI, but has parts to enhance the functionality of for example the Blog content type.
To make things more complicated you can employ ad-hoc content items to build a page that you'd normally do with simple views, but that's an advanced topic :-).
Using Rails, I am building several sites which are very similar. I want to implement these as one Rails app answering to multiple domains, and change what is presented and the processing logic based on the domain name. The areas I need to change/skin per site are:
Views: The fields on a page differ slightly by site. Some sites have more/different fields than others, but there are some that are common across all
Models (which seems best to do this by defining a super class for the main model which varies and implement a subcalss for each site)
Controller logic. There is a lot of similarity but a few small processing differences, including which Model subclass to deal with
CSS (which seems fairly straight forward)
I have already implemented a mechanism which makes the current domain/app name visible to the views, controllers and models.
I was thinking of defining a view partial per site and using ERB logic to include the right one. The controllers seem like the least obvious part.
Any suggestions very much appreciated.
Cheers
Paul
I have implemented something similar for our application, HiringThing (http://www.hiringthing.com)
To do so, we use a before_filter on the application controller that parses request.host and determines what website the request is for. That then sets a variable #site that we reference in views, controllers and models to determine versioning requirements at runtime.
I have a Rails 3.1 "blog" type app and my Post#index has become a sort of overview (or dashboard or sorts) into the whole system. The main content is pulled from the Post model but a sidebar contains info from an Event model, there are other snippets from a News model, etc…
Post#index is a busy action that has to populate many instance variable before /view/posts/index.html.haml gets a call to render and then the many layouts and partials go to work.
Being as some of these other areas are self-contained, so to speak, I'm wondering if there's a better "Rails way" to approach this? Perhaps I should be looking at encapsulating the Event sidebar (which is effectively Event#index) into some kind of entity that can be re-used perhaps in other views? And, if so, how?
What are the options?
You might checkout
http://cells.rubyforge.org/
I would look into widgetizing it. A framework that I looked into in the past was: http://apotomo.de/ This provides a nice clean way to widget"ize" as well as callback functionality (Ajax) for specific widgets.
I've been reading mako / pylons documentation and am having trouble finding good examples / discussion of integrating multiple applications into a single page, so for example, if i had a blog application and an application which just selects a random quotation from a database of awesome quotations. (the example is trivial, just for exposition)
So I want to make a single page which displays both applications,
I'm not sure how to go about writing the templates, i've seen next.body(), do I need to call the controller from the application in a template?
How could I do this on the fly?
Can I just make a model describing the page, and have each application it wants to call as objets in the attributes of the model?
I'm just spitballing here, hoping for a pointer to an example / tutorial i can look over.
Thanks for any advice.
In Django, "applications" are components you develop or choose, then customize, mix and match together to get your final website.
In Pylons, "application" refers to the whole thing you're creating--controllers, models, templates, middlewares, any helper modules, documentation etc. A Pylons application is a bunch of code that can be served as-is by Paster, Apache/mod_wsgi or any other WSGI-supporting web server.
In Pylons, to get, for example, blog posts and random quotations in single page, you'd:
Create separate models for representing and manipulating blog entries and quotes, like myapp.model.Post, myapp.model.Quotation.
Create a controller action that queries models to get X blog posts and a single quotation, put them in data object that will be passed to template.
Create a template that displays both blog posts and quotation on single page. This template can, of course, inherit from some base template or include template fragments, so you don't have to copy-paste common HTML code across many templates.
Hope this helps!