Show taxons instead of products at root url? - ruby

just loosing ideas about proper way to display taxons instead of products in body of spree_application layout.
The spree/home/index.html.erb template renders spree/shared/_products but I would like to render spree/taxons/show instead, for each taxonomy.
No wonder, spree/home/index.html.erb miss taxonomies context so render :template => 'spree/taxons/show' would know nothing about #taxon .
Any idea how simply display taxons instead of products at the homepage, using spree/taxons/show view preferably ?

You should override the spree/home/index.html.erb template in your application's views directory if you want to override the content of this page. As for preparing the content, I would recommend writing a decorator for the HomeController and overriding the index action, like this:
class HomeController < Spree::StoreController
def index
# code goes here
end
end

Related

How to change Url of a module frontend page which is generated by controller in magento?

I am working on a module for video gallery. I can add category from the back end and can upload video with respect to that category.
I can modify the category listing page using <frontname></frontname> in config.xml
I have also noticed that the url of every category in category listing page is managed from model/category.php and the function is:
public function getCategoryUrl()
{
return Mage::getUrl('videogallery/index/cat', array('ci' => $this->getCategoryId()));
}
where videogallery is module name, index is controller name and cat is catAction function in indexController.php, So my every category url is like www.domainname.com/module-Frontend-name/index/cat/ci/categoryId
My question is how can I remove this "index/cat" from every category url?
if "cat" is the name of your action inside IndexController, there's no way to remove it, unless you code a mod_rewrite rule.
Is this what you need?

Rendering a partial in the parent directory in Ramaze

How do I render a partial that's in a different directory (in my case, the parent) than the current view?
<%=render_partial :sidebar%> #looks in the current dir and works as expected
<%=render_partial "/view/sidebar"%> #doesn't work!
Thanks!
You have to specify the right controller that is responsible for the right view:
TheRightController.render_partial :sidebar
If you don't specify the controller class, render_* works for the current action (controller) only, except render_full that does real internal HTTP request.
So, the answer is: If you need shared templates, just create special controller, i.e. called Shared, without any action methods inside, just with many templates in an appropriate view folder and call Shared.render_partial.
Shared.render_partial works like internal request. It renders contents of the controller's action and even the action's method is executed. If you want to render just the view (without executing Shared's action method), use Shared.render_view instead.
Moreover, you can use the internal requesting to prepare some data in the Shared controller's method. For instance, if your sidebar consists of #articles, let's load them in the Shared's sidebar() method. You don't need to load #articles in any other controller that displays the sidebar! You only call "Shared.render_partial :sidebar" in there. This is how to build widget-like web with Ramaze :-)
I found following api in apidock.com, maybe useful for u
# Renders a collection of partials located in a view subfolder
# outside of our current controller. In this example we will be
# rendering app/views/shared/_note.r(html|xml) Inside the partial
# each element of #new_notes is available as the local var "note".
render :partial => "shared/note", :collection => #new_notes
#rebnoob may use (without view directory name, because Rails search on app/view directory)
<%= render "/sidebar" %>
instead of
<%=render_partial "/view/sidebar"%> #doesn't work!

Rails3: one controller many partials for form data submission

I am not sure if this is the best approach but I have a controller that originally I intended to control a show index that renders many partials on it (a header partial and then, has some if else magic to render different partials based on the step the user is in in filling out a form... a form has many sections across several pages). I think ultimately ajax is the way to go but I am not even to that point yet. I am not sure this is the right way to do it, so I guess that is what I am asking... is the many different partials to one controller the way ? or does each "page" of form data have to be broken out into its own controller? allowing the user to fill out form (check boxes, comment section) and click "next" passing the model of the data they are filling out along the way and saving that model in each next?
U may not need several controllers, but 1 controller with some actions may be a good start. =)
Then each action should load only the partial it needs. like u can give the action name to the partial, making easy to know which partial to render.
Or maybe u can try to use wicked.
There is a railscasts for it.
Well, you could use a method to decide which partial to render.
Use this example or do some meta programming.
class YourController < ApplicationController
def index
render :partial => partial_selector(param)
end
private
def partial_selector param
#logic to decide what partial do render
#returns the partial name
end
end

Ruby on Rails: load different partial with radio buttons

I want to load different partials with generated content into a form with ajax.
So how do i make this work?
For example, i have a form with the radio buttons "fruits" and "vegetablles", so when i select one of them, the corresponding partial should be loaded directly into the template dynamically with the right content.
Its a simple form created with scaffolding (edit, show, destroy)
should be prototype normally?
All you do is :
In your controller, you should have the following methods:
def fruits
#myfruit = Fruit.new # what you want!
respond_to do |format|
format.js
end
end
Then, you should have your fruit.js.erb corresponding to that action (suppose you have jQuery here) :
$("#fruits-holder").replaceWith('<%= escape_javascript(render #myfruit) %>');
You then need a partial view like _fruit.html.erb that contains the html you want
As Codeglot stated, if you want more precise answer, post more information about your problem. I cannot be more specific right now.

In a View page within MVC, what is the preferred way to deal with empty variables

When using the MVC design pattern I usually try to make my view files as simple as possible.
Therefore in my View I try not to have lots of code like this:
if page title exists
display page title
else
display 'default page title'
end if
Instead, in my Controller I might use code like this:
if no page title is specified
page title = 'default page title'
end if
load the view (pass page title as a parameter)
Is this the best way to tackle this issue?
Keeping this if-else condition in the controller level is a better idea than moving into views. (if you can otherwise it's alright)
It will make your views look good !!!!

Resources