rails app - Friendly_id cut url - ruby-on-rails-3

my rails application generates the following URL :
www.mysite.com/chicago?area_id=4
I'd like to "cut" it to :
www.mysite.com/chicago
Is it possible to do so using friendly_id ?
Thanks

Related

Devise redirection issue

I'm using devise in my rails3 project. I need to redirect user to different page once logged-in. Without overriding sessions controller how can I do this?
Question looks like a duplicate of https://stackoverflow.com/a/12854498/790737
Try putting this in you ApplicationController:
def after_sign_in_path_for(resource)
different_page_path # this should be a path helper
end
I assume you know how to use path and url helpers, and that you can use
rake routes
to list them. Good luck.

Devise user authentication on Rails 3: routing error on default views

I followed the basic steps to add authentication to Rails using Devise from their page, but every time I try to visit a default page (such as the Sign In or Sign Up pages), I get:
Routing Error
No route matches {:controller=>"devise/Home"}
This happens whether I link to the page in a view using
link_to('Register', new_user_registration_path)
or just visit "/users/sign_up".
This is a different error from when I visit a page with no route defined (No route matches [GET] "/users/bad_example"), and
devise_for :users
is already present in my routes.rb. I have even tried generating views (rails g devise:views) to no avail. It looks like Devise isn't generating/using a controller or some such. How do I go about fixing this?
Here are some files that may help:
routes.rb
rake routes output
It turns out the problem was not with Devise, but with my routes file. I have fixed my routes file as seen at http://guides.rubyonrails.org/routing.html and now this works properly.

Rails 3.1 force .html instead of no extension

One of my clients wants his new Rails application to look more like his traditional web site. He wants to know if I can force urls to have a file extension, preferably .html.
I don't want to hard-code the extension in routes.rb as
match ':controller/:action/:id.html'
(or similar) because the client also wants to have a respond_to-style JSON API which requires the use of .:format.
Can this be done?
Just as Mattias Wadman suggested, in config/application.rb add:
AppName::Application.default_url_options = { :format => "html" }
But also change config/routes.rb to:
root :to => 'pages#home', :defaults => { :format => "html" }
Im no Rails routing expert but I tried to force HTML format by changing the default URL options and at least the URL helpers seams to generate .html URLs now, it's a start.
config/application.rb (at the bottom)
AppName::Application.default_url_options = {:format => "html"}

creating a launch page in rails app

I am planning to create an app in rails but first I want to make a launch page. Having never made a launch page I am curious as to how others are doing it?
Do you creae a small rails application with controller and model that just collects email addresses? and then deploy the rails app? I'd prefer this way but it seems like an overkill to deploy a rails app just for a launch page...?
Also, how do you modify the routes file so that if users type anything after the url then only page that shows up is the laungh page.
Meaning, if my launch page is at http://mycoollaunchpage.com then if users mess around and type http://mycoollaunchpage.com/lkjlkjljk then it should redirect back to http://mycoollaunchpage.com
Your idea sounds good. Just a page with an email signup form would work well.
To redirect back to your home page, make a route glob in your routes.rb file, and have an action in your controller that just redirects back to your root.
# in routes.rb
match "*whatever", :controller => 'pages', :action => 'redirect_to_root'
# in your pages_controller.rb file
def redirect_to_root
redirect_to "/"
end
There is an awesome rails plugin available for this very requirement of yours ;)
https://github.com/vinsol/Launching-Soon/

Rails 3 namespace routing

I have an admin namespace and a scaffold of companies placed out of the admin namespace.
I wanted to put the companies into admin namespace
Then I put the companies_controller into admin directory and changed the definition to
class Admin::CompaniesController < Admin::AdminController
and put the companies views into the admin directory in /app/views/
and put the companies_helper into admin directory and now it looks as follows:
module Admin::CompaniesHelper
end
The namespace in routes.rb:
namespace :admin do
root :to => "companies#index"
resources :companies
end
When I go to localhost:3000/admin I get this error:
undefined method `company_path' for #:0xb696b408>
Now please tell me how to edit the links to make the links work properly?
When you moved the controller in to the admin namespace you changed routes to the links created in the scaffolded templates. For example if your templates use company_path the links would change to admin_company_path.
To view the routes within your application at any given point in time, run "rake routes" from the command line within the root of your rails application. This will show you all the routes within you application
Since company is under the namespace admin you have to prefix the path with admin.
Like so:
admin_company_path(#company)
See this Rails guide for more info on Rails routing and namespaces.
I got the kind of ugly solution but it works. I generated a new scaffold but differently:
rails generate scaffold Admin::Companies
instead of
rails generate scaffold Companies
but I still don't understand how the helpers make url for the resources :(