Forum: Ruby on Rails Fix URL redirecting

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
800e63992b25e6d1cf824d45d98b8ccc?d=identicon&s=25 craig w (Guest)
on 2007-02-09 18:28
(Received via mailing list)
I tried posting this once but had problems with Google Groups.

Hi,
   I watched the rails screencast on creating a blog in 15 minutes.
I followed along got it working on my home PC and I then uploaded it
to my web host.  So I have,

/home/<username>/blog

  I had to change some config in the blog app (i.e. production mode,
db settings).

I then created a directory....

cd ~/public_html/bor

And a symlink to point to my blog app....

ln -s ~/blog/public ~/public_html/bor

I deleted the blog/public/index.html and I modified blog/config/
routes.rb to contain the following line:

map.connect '', :controller => 'blog', :action =>'index'

I did that so when someone goes to mysite.com/bor/ they would get
directed to what is the index action in my blog_controller.

Ok, so things are working and I can see my blog posts when I go to,
mysite.com/bor/   Now if I click on post I get redirected to
mysite.com/bor/blog/show/1  .....and from that page if I click "back"
I end up at mysite.com/bor/blog/list  ....basically all the links look
like mysite.com/bor/blog/<blah blah blah>  instead of what I hoped to
see, mysite.com/bor/<blah blah blah>.

Any ideas?

If it helps, my blog_controller.rb has the following method for the
"index" ...

def index
 list
 render :action => 'list'
end
Thanks!
72eb65fa089082d3bd8b38a5596ad331?d=identicon&s=25 Keynan Pratt (keynan)
on 2007-02-09 19:53
craig w wrote:
> I tried posting this once but had problems with Google Groups.
>
> Hi,
>    I watched the rails screencast on creating a blog in 15 minutes.
> I followed along got it working on my home PC and I then uploaded it
> to my web host.  So I have,
>
> /home/<username>/blog
>
>   I had to change some config in the blog app (i.e. production mode,
> db settings).
>
> I then created a directory....
>
> cd ~/public_html/bor
>
> And a symlink to point to my blog app....
>
> ln -s ~/blog/public ~/public_html/bor
>
> I deleted the blog/public/index.html and I modified blog/config/
> routes.rb to contain the following line:
>
> map.connect '', :controller => 'blog', :action =>'index'
>
> I did that so when someone goes to mysite.com/bor/ they would get
> directed to what is the index action in my blog_controller.
>
> Ok, so things are working and I can see my blog posts when I go to,
> mysite.com/bor/   Now if I click on post I get redirected to
> mysite.com/bor/blog/show/1  .....and from that page if I click "back"
> I end up at mysite.com/bor/blog/list  ....basically all the links look
> like mysite.com/bor/blog/<blah blah blah>  instead of what I hoped to
> see, mysite.com/bor/<blah blah blah>.
>
> Any ideas?
>
> If it helps, my blog_controller.rb has the following method for the
> "index" ...
>
> def index
>  list
>  render :action => 'list'
> end
> Thanks!

uh huh...


simplest solution rename blog controller to bor controller and move it
up a directory

then read agile development in rails by the pragmatic programmers group.
800e63992b25e6d1cf824d45d98b8ccc?d=identicon&s=25 cdvr (Guest)
on 2007-02-09 20:21
(Received via mailing list)
> uh huh...
>
> simplest solution rename blog controller to bor controller and move it
> up a directory


...I am reading the agile book now (is there a certain section you
recommend for more information?).

Anyways, what do you mean by "move it up a directory"?  Move the
bor_controller somewhere?  The controller is kept in app/controllers,
sorry just not understanding what you mean.

Thanks for the help though.
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (squeegy)
on 2007-02-09 20:47
craig w wrote:
> ....basically all the links look
> like mysite.com/bor/blog/<blah blah blah>  instead of what I hoped to
> see, mysite.com/bor/<blah blah blah>.
>
> Any ideas?

That because it's all going through the 'blog' controller.  If you have
other controllers, your url would look like:

  /bor/comments/show/1
  /bor/products/new

You can setup a custom route that looks like:

  map.blog ':action/:id',
        :controller => 'blog'

Now you can do:

  url_for(:controller => 'blog', :action => 'show', :id => 123)

Or even better:

  blog_url(:action => 'show', :id => 123)

and get the url:

  /bor/show/123

Just keep in mind that if you do add more controllers in the future
rails routing will have a hard time figuring out what goes to the blog
controller and what goes to the other controllers.  This is why its best
to keep controller names in the url.
800e63992b25e6d1cf824d45d98b8ccc?d=identicon&s=25 cdvr (Guest)
on 2007-02-09 21:00
(Received via mailing list)
> That because it's all going through the 'blog' controller.  If you have
> other controllers, your url would look like:
>
>   /bor/comments/show/1
>   /bor/products/new

so can I get rid of "bor" altogether and somehow make my blog
application accessible, even though it is stored at,

/home/<user>/blog

?

I'd prefer not to even have the "bor" and symlink....but I didn't know
how else to expose blog/public to the web.

Thanks.
800e63992b25e6d1cf824d45d98b8ccc?d=identicon&s=25 cdvr (Guest)
on 2007-02-10 05:41
(Received via mailing list)
...bump...
This topic is locked and can not be replied to.