i have some controllers, i want to put categories names into layout, like menu, what i could see in all pages. Is there a easy sollution to do this?
Use : render :layout => 'yourcustomlayout'
in your specific action.
Use general layout for whole application. You can specify one layout for an application and even override it wherever required.
See here for details and near exact example for your case.
Related
I tried the simple approach: editing the Contact page in the admin interface and selecting my new template within the Advanced Options section. But the form does not get displayed.
I also generated the override views:
rake refinery:override view=refinery/inquiries/inquiries/*
But looking at the app\views\refinery\inquiries\inquiries\new.html.erb file, I did not see an obvious solution to this issue.
I found this issue on github but it does not offer much detail: https://github.com/refinery/refinerycms-inquiries/issues/45
I suspect a big part of the issue is that when I change the template setting under Advanced Options, it's changing the view from the default inquiries new.html.erb to one of the standard view options. The problem is inquires extension new view is not listed as an option.
The short answer here is: you can't.
In the course of struggling with this, I came to realize that in most cases you probably don't want to be switching layouts. Not in the casual manner that I was, anyway.
What I really wanted were alternate page views. The basic web page layout and styling can be fully modified through views.
Realizing this changed my objective. I didn't need to change the layout for the inquiry pages. I needed to match the inquiry page views to my default page view. I was able to do this by overriding the inquiries extension's new and thank-you views and editing those files so that the markup and styling matched that of my default page view.
Simple enough. The only downside is it's a bit un-DRY. If I were to alter my page view, I now would likely have to repeat the changes in those two views as well.
I have followed the instructions found on the Guides for building a custom layout:
NOTE: The portfolio is an engine of my own, not the refinerycms-portfolio.
config.layout_template_whitelist = ["application","portfolio"]
config.use_layout_templates = true
Created a portfolio.html.erb under app/views/layouts and copied everything from the application.html.erb except for the <header> section: I do not want the menu and logo shown in this layout, but all the rest
I can now see the layouts in the back end.
If I choose my portfolio page and press preview, the layout renders without the menu
However, if I go directly to /portfolios, the 'application' layout renders and not the 'portfolio'
Any ideas please?
Thank you...
Well, it seems that the namespacing introduced in the latest RefineryCMS versions prevents the layout to be picked up automatically, thus you need to manually instruct the Controller to pick up the layout in question. To this case I had to add:
render :layout => 'layouts/portfolio'
in my portfolios#index action.
Hope this helps...
Is there a way to render a partial view with accompanying code in rails?
For instance: I want to be able to create a partial view which will show the top 5 foobars on my site. This partial needs accompanying code to retrieve some foobars from the database, rank them according to an algorithm, and then output the view with the top 5.
I want to be able to include this partial on any page I fancy, preferably just by using something like
<%= render :action => "top_five_foobars" %>
Is this doable? I'm used to asp.net mvc where you can create an action that runs some code and returns a partial, but it seems like in rails it returns simply the template...
If google get you here, you might be looking for cells
Cells are view components for Rails. They are mini-controllers with
their own MVC stack, can invoke logic and render views. They bring
back OOP to Rails' view layer and make writing reusable portlets for
your applications fun.
You need something like a shopping cart, which appears on almost
every page of your app.
You wouldn't use a partial and a helper, would you?
It might not be the cleanest way, but what I did is that I created a helper method in the Application Controller that retrieves the top 5 foobars. Then I call this method in the views. I also cached the part of the view that shows the results.
I have a problem and I dont know how to solve it.
I have a user that log in a web site, and I identify them by session[:user_id] and user has a status page that is defined in user_controller and in status view.
So, I would like to make one page for admin, to see all the statuses from all users on one page, using already written controller and view.
Is that possible?
I could rewrite some of the code, so that I could call with params, like ?user_id=70 and then set session[:user_id]=params[:user_id], but it would be painful if I will have to rewrite whole statuses, beside i would have to maintain same code on 2 different places.
Thank you.
Dorijan
If you need more functionality in your controller, you can add more actions to it. You can also do that in a resourcefull way.
On the other hand it usually is best practice to keep controllers thin.
See: ActionController
In order to make your views reusable, you should use partials.
You could make a _user_status partial.html.erb and render a single partial for a user render all of them for an admin.
Checkout: Layouts and Rendering in Rails
I have a Users controller and a layout called 'users.html.haml'. The problem I'm having is that Rails does not seem to find the users layout automatically. I have to tell every action in the Users controller to render the layout. If I don't tell the action which layout to use, it renders no layout at all.
Currently, the layout renders only if the controller action has this line:
render :layout=>'users.html.haml'
Any ideas? Thanks in advance.
UPDATE:
I'm an idiot. I overwrote the "initialize" method in application controller, and it was causing all layouts to be loaded improperly unless I specifically told the action which layout to use. Didn't have anything to do with haml after all. Thanks for all your answers.
You havev the users.html.haml in your
app/views/layouts
directory right? And not your app/views/users directory?
Try using this:
render :layout=>'users'
NOTE: I have removed the .haml.html part, because that isn't necessary
Other this you can do is to have the layout in top of the controller, like
layout 'users'
Edit: and like #Noli said, your layouts should be in app/views/layouts path