Building main page with admin controller

I am trying to build a main page with a customized view containing login
control and several 'div with menus and buttons all combined into one
page. I believe I have to use admin controller. Is there an article that
shows how to do this?

I am describing what I am trying to accomplish:
I want to create a main welcome page. So I ran script/generate
admin/welcome. This created welcome controller
Then I wanted to attach this welcome controller to the main
application.html.erb
In the application.html.erb file I want to show a ‘login’ control and
two action buttons: ‘suppliers’ and ‘contractors’. This means somehow I
have to create three controllers: ‘login’, ‘suppliers’, and
‘contractors’.

  • Should I create all three controllers under admin?
  • How to connect my welcome controller to these three controllers and
    get to display the application.html.erb file
    I do not know if I am thinking in the correct direction also? Please
    help?

Vishwa R. wrote:

I am trying to build a main page with a customized view containing login
control and several 'div with menus and buttons all combined into one
page. I believe I have to use admin controller. Is there an article that
shows how to do this?

You are going to have to start simple and understand the mechanics of
rails before you continue any further.

Your first item of the day should be learning more about rails:

http://guides.rubyonrails.org/

As for your question about how layouts work with rails… Inside of
your app, the layouts folder contains specific layouts which act as
wrappers for your content.

If you just want to make it simple for starters, remove all of the
layouts “except” application.html.erb which will be your main wrapper
layout file.

Inside of this file you would place something similar:

http://gist.github.com/285321

The yield is where your content will go from your views. This is a very
bare bones idea of a layout I’m showing. It’s just enough to get you
started though. You’ll have to go visit http://guides.rubyonrails.org/
in order to read more about rails and what you want to accomplish.

OK. I got the welcome page working to look at application.html.erb file
by creating a controller ‘home’ and updating the routes.rb with a line
map.root :controller => “home”
Now, if I customize home/index.html.erb then I can display whatever I
need to - gets called at <%= yield %>, I hope - Is this the right
approach?

I still trying to understand yield(:head) and yield(:title) - can you
pl. tell me?

Vishwa R. wrote:

Thank you. I am new and sorry for asking complicated questions, without
reading.

I copied the code you suggested in application.html.erb file in
view/layouts dir in my project.
When I start the server and say http:localhost/3000 it shows default
ruby welcome page.

  • How to I display contents of application.html.erb file.
  • Also what is yield(:head} and yield(:title)

When I was looking at other exmaples, they all create a model and then
change the model.html.erb file to display as default view. But for my
welcome page I don’t have a model or a controller? So how to invoke the
application.html.erb file

Alpha B. wrote:

You are going to have to start simple and understand the mechanics of
rails before you continue any further.

Your first item of the day should be learning more about rails:

http://guides.rubyonrails.org/

As for your question about how layouts work with rails… Inside of
your app, the layouts folder contains specific layouts which act as
wrappers for your content.

If you just want to make it simple for starters, remove all of the
layouts “except” application.html.erb which will be your main wrapper
layout file.

Inside of this file you would place something similar:

http://gist.github.com/285321

The yield is where your content will go from your views. This is a very
bare bones idea of a layout I’m showing. It’s just enough to get you
started though. You’ll have to go visit http://guides.rubyonrails.org/
in order to read more about rails and what you want to accomplish.

Thank you. I am new and sorry for asking complicated questions, without
reading.

I copied the code you suggested in application.html.erb file in
view/layouts dir in my project.
When I start the server and say http:localhost/3000 it shows default
ruby welcome page.

  • How to I display contents of application.html.erb file.
  • Also what is yield(:head} and yield(:title)

When I was looking at other exmaples, they all create a model and then
change the model.html.erb file to display as default view. But for my
welcome page I don’t have a model or a controller? So how to invoke the
application.html.erb file

Alpha B. wrote:

You are going to have to start simple and understand the mechanics of
rails before you continue any further.

Your first item of the day should be learning more about rails:

http://guides.rubyonrails.org/

As for your question about how layouts work with rails… Inside of
your app, the layouts folder contains specific layouts which act as
wrappers for your content.

If you just want to make it simple for starters, remove all of the
layouts “except” application.html.erb which will be your main wrapper
layout file.

Inside of this file you would place something similar:

http://gist.github.com/285321

The yield is where your content will go from your views. This is a very
bare bones idea of a layout I’m showing. It’s just enough to get you
started though. You’ll have to go visit http://guides.rubyonrails.org/
in order to read more about rails and what you want to accomplish.

<% title(“Administration Page” %>

should read…

<% title(“Administration Page”) %>

My apologies.

Vishwa R. wrote:

OK. I got the welcome page working to look at application.html.erb file
by creating a controller ‘home’ and updating the routes.rb with a line
map.root :controller => “home”
Now, if I customize home/index.html.erb then I can display whatever I
need to - gets called at <%= yield %>, I hope - Is this the right
approach?

I still trying to understand yield(:head) and yield(:title) - can you
pl. tell me?

The idea behind yield flows with a method called content_for().

In your application_helper.rb file in the helpers folder place the
following:

def title(page_title)
content_for(:title) { page_title }
end

Now then, let’s say you have a title in your layout that shows this:

<%= "My Home Page" || yield(:title) %>

On every single page that a person opens up on your site that uses the
layout wrapper, it would show the same exact title of “My Home Page”.
You wouldn’t want the same title for every page would you? No, probably
not.

So, with the helper file I just showed you how to make you could do the
following:

Let’s say you have a new page called index.html.erb for a new controller
called administration. So inside the index.html.erb you could place at
the top of that file the following line:

<% title(“Administration Page” %>

Now then, whenever that pages loads it will automatically see that you
are calling a content_for method for title(“some label”) and the helper
file will place the new title there instead of the old one. So, on the
admin page, you will see Administration Page and not My Home Page.

This allows you to decide what type of content to use on different
pages.

Let’s add another helper for the head.

def head(css_file)
content_for(:head) { stylesheet_link_tag “#{css_file}” }
end

Again, using this example, you might want to specifically overwrite your
css with some specific css file that should only be used on one or two
pages on your site. On these pages within your views, you could do:

<% head(‘my_custom_css’) %>

Which will be yielded where?.. That’s right, in the head section where
you wanted it to go. It’s the same thing as placing a
stylesheet_link_tag ‘my_custom_css’ in the head of that page only.

Yielding content_for elements in specific places allows you to define
specific content to appear in certain places of the layout, but only on
certain pages.

I hope that helps you understand that a little bit. I would try it out
on several pages and see how it works.

Please keep in mind that I’m not advocating loading multiple css files.
But, there are times you might require multiple css files on a specific
page. So, I’m just supplying you with a basic understanding of how to
use helpers to define content_for methods on specific pages which are
included within your layout only for those specific pages.

I hope I made things clear enough for you.

Take care.

Thanks a lot for your help!

Alpha B. wrote:

<% title(“Administration Page” %>

should read…

<% title(“Administration Page”) %>

My apologies.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs