I have a pages controller and my pages view directory.
Say I have a settings page that when visited displays a few links e.g. privacy, notifications, etc.
When each link is click the content of the pages for those links are loaded within the same page.
Now in my pages view directory I want to organize things slightly.
So instead of having the pages directory and all the view templates in that directory. I would like to have "pages" then "settings" then in the settings directory I would like to place my views files "privacy.html.erb", "notifications.html.erb" etc.
How can I do this and still have rails 3 know what view file to load?
Just using good old render:
render 'pages/settings/privacy'
to load privacy.html.erb.
Related
I'm using i81n for localization and the file structure is as shown below. I'm wondering if it's possible to add a single page for the secondary language only.
locales (all the data for non-blog pages)
en.yml
es.yml
source
localizable (all the pages that are shared in both languages)
I've tried adding a .html.erb file directly inside source folder which successfully added a page for English site only (en is the root site). But is there any ways I can add the page just for the Spanish site? Thanks!
Updates: Also tried adding a ES folder inside source and put the .html.erb file in their. This successfully created the page under /es but it's getting header and footer in English instead of Spanish.
I'm currently working on a project which has ROR in backend, I need to add a noscript tag to every page in the system to show a banner to the user.
Does ROR provide an easy way to add a piece of html to every page?
Add it to the application layout file /app/views/layouts/application.html.erb. That file gets loaded for every view unless you have disabled this layout or have used a different layout.
If you have multiple layouts then place the <noscript>...</noscript> in a partial and render the partial in all the layouts.
I am using a simple layout demo in my rails3 application
simple layout demo
in this demo there are 5 panel north,south,east,west,center
when I load my project this all panel show in each and every page.
instead of I want to some specific panel in different different page
give some idea how can i do that
Is the code from the simple layout demo all in your /app/views/layouts/application.html.rb? If so, rails will render everything from that file in every view. Since the jQuery code that does all of the stuff in that demo is in that same file, there may be no easy way to make that work with rails. The only thing I could think to do would be to have different .js files for different pages. each of these separate files would have jQuery code that creates the layout for that page, and is linked to that page using content_for and javascript_include_tag. I'm writing an app that uses jQuery UI and this is how I've had to do it. I created sub folders in my /public/javascripts directory that I named after my models to make it easier to keep all the .js files sorted.
I'm rails I've been building a web app.
But the web app is completely different than what the landing page (sign in, register, about, etc should look like)
How do rails developers handle this? Different layouts? Different CSS files? etc..
what's cleanest? Thanks
You could create a HomePage controller (with associated views), and write the index action for that.
If the layout for the home page is going to be different from the application's again, then in the app/views/layouts/ folder, create a home_page.html.erb template. This will automatically be used by a HomePageController instead of the default application.html.erb template.
I have a flash media player (similar to lala.com) that needs to continue to stream while people click around. I don't want to use an iframe.
So, I need to dynamically load all site pages with ajax no matter what link people click on.
I've got this working with Rails and JQuery for a single page. With this method I have to place a file.js.erb file for whatever controller is called. Example: example.com/home is called and I have to have an index.js.erb in the views home dir to respond to this.
I used:
http://railscasts.com/episodes/174-pagination-with-ajax
to get this to work on one page, but it wouldn't be DRY at all to copy .js.erb files to every controller.
Is there something I can do with the main application_controller or even with routes.rb?
I found a way to do this. You can load whatever pages you want via the jquery load method.
$('#result').load('ajax/test.html #container');
They will then be placed in the div with the #result id.
You can also specify a page fragment with #container so you only load the part you want.
This allows all your controllers to stay in tact etc with no extra js.
This is really going to impact your visibility to search engines. I also think it will mean you need to think about the flow of your controllers. Rather than having controllers responding with views that represent a page, controllers will respond with snippets of HTML/JSON/etc that get injected into the home page. Your home page acts as a coordinator, loading the content in and out. Perfectly fine to have js.erb files in each view folder ... as they should be returning content specific to an individual controller.