So lets say I have the following rails app:
所以我想说我有以下rails应用程序:
myrailsapp.com
myrailsapp.com
and if you want to view and item here, its myrailsapp.com/items/1
如果你想在这里查看和项目,请查看myrailsapp.com/items/1
now lets say I buy, mrsap.com
现在让我说我买,mrsap.com
lets say item 1's name is "frank"
让我们说第1项的名字是“坦诚的”
and I want the item's name such as "Frank" to become the short url.
我希望项目的名称如“Frank”成为短网址。
So mrsap.com/frank would go to myrailsapp.com/items/1
所以mrsap.com/frank会去myrailsapp.com/items/1
Any ideas for how I can go about doing this?
关于如何做到这一点的任何想法?
2 个解决方案
#1
1
If you are using Rails 3 you could do this with a request based constraint in your routes. Something like this.
如果您使用的是Rails 3,则可以在路由中使用基于请求的约束来执行此操作。像这样的东西。
match "/:name" => "items#show_by_name", :constraints => {:host => "mrsap.com"}
And in items_controller.
并在items_controller中。
def show_by_name
@item = Item.find_by_name(params[:name])
render :action => "show"
end
#2
0
It's probably best to run it as a separate app. You pass the app a full URL, it creates a slug for a tinyurl. Separation of concerns is always best.
最好将它作为一个单独的应用程序运行。您将应用程序传递给一个完整的URL,它会为一个小小的创建一个slug。关注点的分离总是最好的。
#1
1
If you are using Rails 3 you could do this with a request based constraint in your routes. Something like this.
如果您使用的是Rails 3,则可以在路由中使用基于请求的约束来执行此操作。像这样的东西。
match "/:name" => "items#show_by_name", :constraints => {:host => "mrsap.com"}
And in items_controller.
并在items_controller中。
def show_by_name
@item = Item.find_by_name(params[:name])
render :action => "show"
end
#2
0
It's probably best to run it as a separate app. You pass the app a full URL, it creates a slug for a tinyurl. Separation of concerns is always best.
最好将它作为一个单独的应用程序运行。您将应用程序传递给一个完整的URL,它会为一个小小的创建一个slug。关注点的分离总是最好的。