Deep beginning

Hey guys,
it’ll be kinda silly question, but I was working for two years on my
bachelor’s thesis using RoR…but I have never found out, how to do that
when I type in the browser the address and port, there will be a
homepage
shown…is there some easy way?

Thanks in advance
Jan K.

You mean setting your routes so that you can tell Rails where your
homepage is at when you preview using localhost?

In rails 3, do something like this:

Home Page Route

root :to => “site#home”

Site Routes

match ‘/’, :to => “site#home”

So when you go to http://localhost:3000, rails will route to your
homepage.

I’ve got rails 2.1 unfortunately.
Isn’t there any more peaceful way to do it without declaring war to half
of
the application by changing routing?

btw, my app is available on the address tinyurl.com/skurt, please feel
free
to check it out.
I have made there two controllers: home and Rolldance (rolldance is from
some kind of turorial)
home have bunch of actions, but there is view only for action wow
rolldance have actions both with views index and o_nas
What I’m trying to do is simply access those pages and I’m totally
unsuccessful :frowning:
Jan K.

2010/7/21 thereddestruby [email protected]

On Tue, Jul 20, 2010 at 3:21 PM, Jan K. [email protected]
wrote:

Isn’t there any more peaceful way to do it without declaring war to half of
the application by changing routing?

What are you talking about?

You use routing to match URLs to the content you want to serve.

If you’re not getting the results you expect, run rake routes to see
what’s actually configured.


Hassan S. ------------------------ [email protected]
twitter: @hassan

http://www.tutorialspoint.com/ruby-on-rails-2.1/rails-routes.htm

http://guides.rubyonrails.org/getting_started.html see section 4.2
Although its for 2.3, 2.1 looks to be similar.

“You use routing to match URLs to the content you want to serve.”
Are you telling me, that the default routing setting do not work like
this:
my ip: 1.2.3.4
my port: 3000
controller name: c
action name: a
this implies the address http://1.2.3.4:3000/c/a.html
???

I’m asking, because I believe it work like that which means, when I
start to
change it, I’ll mess the whole app up.

Jan.

2010/7/21 Hassan S. [email protected]

“If you’re not getting the results you expect, run rake routes to see
what’s actually configured.”

[email protected]:~/www/skurt$ rake routes
(in /home/skurt/www/skurt)
/:controller/:action/:id
/:controller/:action/:id.:format

Now I see I really don’t want to mess with it :frowning:

Jan

2010/7/24 Jan K. [email protected]

Well, after a while trying I found a way to do it right. The first time,
I
created just controller
script/generate controller home
and then created actions by editing the file
app/controllers/home_controller
like this:
def action1
end
def action2
end

and for every action I created a file like this
app/views/home/action.html.erb
and it didn’t work (that’s the point where you were suggesting routing)

but the only thing I needed was to destroy all the work done and use the
command
script/generate controller home action1 action2…

and voi’la myIP:3000/home works now :slight_smile:

BUT! What I’m trying to figure out now is addressing inside of the app.
I’m
trying to set up a background for the page but the relative path
starting
from the route of the app doesn’t work and unfortunately the absolute
path
doesn’t work either.
So where is the root of the relative path?

Jan

2010/7/24 Jan K. [email protected]

Thanks a lot :slight_smile:
Jan

2010/7/24 Hassan S. [email protected]

On Fri, Jul 23, 2010 at 5:22 PM, Jan K. [email protected]
wrote:

Well, after a while trying I found a way to do it right. The first time, I
created just controller

and it didn’t work (that’s the point where you were suggesting routing)

but the only thing I needed was to destroy all the work done and use the
command
script/generate controller home action1 action2…

and voi’la myIP:3000/home works now :slight_smile:

because the routes.rb file has been updated, which you could have
easily done manually :slight_smile:

BUT! What I’m trying to figure out now is addressing inside of the app. I’m
trying to set up a background for the page but the relative path starting
from the route of the app doesn’t work and unfortunately the absolute path
doesn’t work either.
So where is the root of the relative path?

Static resources are typically served from /public/* so e.g. an image in
{RAILS_ROOT}/public/images/foo.png would be accessed by the URL
http://hostname:port/images/foo.png

HTH,

Hassan S. ------------------------ [email protected]
twitter: @hassan

In the tutorial here:
http://guides.rubyonrails.org/layouts_and_rendering.html
a have found a problem.
There is stated: “By default, the file is rendered without using the
current
layout. If you want Rails to put the file into the current layout, you
need
to add the :layout => true option.”
…but where? I tried the view file and the controller file and neither
doesn’t work.

Jan

2010/7/24 Jan K. [email protected]

Well, I figured now, that there is really no need to tell the controller
to
use the layout, it makes it by default, BUT…I’m still unable to set up
the
wallpaper. I moved the picture to the directory
public/pic/
and add the address pic/darkKnight_wide.jpg to the layout file.
But it only affected the index view file, in others there is still the
same
link for the background, but the background isn’t shown.

Well, I figured this one out now also…apparently there is huge
difference
between those two strings:
/pic/picture.jpg
pic/picture.jpg
Which I guess means there are no relatives paths in rails, right?

Jan

2010/7/24 Jan K. [email protected]

On Jul 24, 1:06 am, Jan K. [email protected] wrote:

Well, I figured this one out now also…apparently there is huge difference
between those two strings:
/pic/picture.jpg
pic/picture.jpg
Which I guess means there are no relatives paths in rails, right?

It’s better to use the image_tag helper than code full paths to images
in your app. The convention is like this:

  1. create an images subdirectory under public in your rails app
  2. link to an image via the image_tag helper

So in your case you’d create public/images/picture.jpg and link to it
in a template like <%= image_tag “picture.jpg” %>.


miles

On Jul 24, 9:06 am, Jan K. [email protected] wrote:

Well, I figured this one out now also…apparently there is huge difference
between those two strings:
/pic/picture.jpg
pic/picture.jpg
Which I guess means there are no relatives paths in rails, right?

Absolute and relative paths are indeed very different. This doesn’t
have much to do with rails though - it’s just the way that html
works.
What do you mean by ‘there are no relative paths in rails’ ?

Fred

To Frederick:
“What do you mean by ‘there are no relative paths in rails’ ?”
As I understand the difference, there is some point in the computer
directory tree, where is said I’m working, for example
/home/myusername/RubyApps/rails/default
now if I want to link something inside of that directory, you just type
name
of the file, because some kind of magic or more than human power will
know
it should first look there.
On the other hand the absolute path is recognized by starting with the
only
root of the whole computer filesystem, like “/” or “C:”

…so if I have to use “/” in the pseudo-relative path like this, then I
guess I’m using absolute path from the relative point described above,
which
I absolutely don’t get.
And if it really is either of those, I can’t imagine usage of the other
one.

To cageface:
Sir, I may be an idiot, but it doesn’t work.
I have pictures in public/pic
the picture filename is darkKnight_wide.jpg
and I’m reffering to it like this:

> and I know nothing abou html, but there is no way that the 'higher power' translating that ruby babbling into html can know which subdirectory in the public directory it should try.

To everyone:
I’m trying to follow this tutorial to create a password checker in my
app:
http://www.devarticles.com/c/a/Ruby-on-Rails/Login-Systems-and-More-with-Ruby-on-Rails/
I followed until like two thirds of article and crashed on this one:
"Create an entry in the users table, start the server, and you’ll find
that
you can log in from http://localhost:3000/user/login, and view your
account information from http:// localhost:3000/user/my_account. "
a created a login name and password in the correct database table, but,
when
I type in to my browser myIP:3000/user/login it’s giving an error
message
saying that it cant apply something on [].
I almost completely don’t know what exactly am I doing, but I looked
into
the database and found the password there…the exact password, which is
I
would say lame, isn’t it? There should be hash or something (not
ruby-hash,
but you probably know).
Because of that I’d say that this tutorial is kind of crapy and I wanted
to
ask anyone if you know about any better, I’d love to read it.

Regards
Jan

2010/7/24 cageface [email protected]

cageface:
Oh, I get it now, this awesome trick works, but you have to set you app
up
EXACTLY, like it is said…I don’t get those ‘features’
but thanks.

Jan

2010/7/24 Jan K. [email protected]

On Jul 24, 5:26 pm, Jan K. [email protected] wrote:

…so if I have to use “/” in the pseudo-relative path like this, then I
guess I’m using absolute path from the relative point described above, which
I absolutely don’t get.

Almost - you’re looking at it from the point of view of your computer
whereas you need to be looking it at from the point of view of the
web browser & web server: / doesn’t mean the root of your hard drive,
it means the root of your website, which for a rails app is
your_rails_app/public. Relative paths are relative to the page the
browser is currently sitting on, so if your browser is displaying
http://foo.com/blah then an image with path ‘pics/logo.png’ will
request http://foo.com/blah/pics/logo.png whereas ‘/pics/logo.png’
will request http://foo.com/pics/logo.png

Fred

I have moved all pictures in the images directory and it works now for
the
pictures.
It unfortunately doesn’t work for background, or I don’t know how to
throw
it.

And one little question…how do I align pictures inserted into web like
this? I can’t google it.

Jan

2010/7/24 Jan K. [email protected]

On Jul 24, 5:26 pm, Jan K. [email protected] wrote:

I almost completely don’t know what exactly am I doing, but I looked into
the database and found the password there…the exact password, which is I
would say lame, isn’t it? There should be hash or something (not ruby-hash,
but you probably know).
Because of that I’d say that this tutorial is kind of crapy and I wanted to
ask anyone if you know about any better, I’d love to read it.

That is indeed a bad way to do things. You might want to look at
authlogic which is what a lot of people use these days.
restful_authentication also used to be quite popular.

Fred

On Sat, Jul 24, 2010 at 9:57 AM, Jan K. [email protected]
wrote:

It unfortunately doesn’t work for background, or I don’t know how to throw
it.

What exactly does that mean? How are you trying to set “background”?

And one little question…how do I align pictures inserted into web like
this? I can’t google it.

You need to study basic HTML and CSS if you’re going to be doing
web apps, I’m afraid. And I’m sure you can easily google up some
tutorials on those subjects :slight_smile:


Hassan S. ------------------------ [email protected]
twitter: @hassan

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