How do I redirect to root – public/index.html?

You can assign a named route to a static file by passing any non-empty string as :controller and the path to the file as the :action for the route: Application.routes.draw do root :controller => ‘static’, :action => “https://stackoverflow.com/” # or # root :controller => ‘static’, :action => ‘/public/index.html’ end # elsewhere redirect_to root_path # redirect … Read more

Passing param values to redirect_to as querystring in rails

The ‘Record’ form of redirect_to uses the second argument only for the response status. You’ll have to use another form of redirect_to, like the ‘String’ form. e.g.: redirect_to thing_path(@thing, :foo => params[:foo]) which will work for nested params[:foo] params like you mentioned. Or, as Drew commented below, you can use polymorphic_url (or _path): redirect_to polymorphic_path(@thing, … Read more

Ruby formatting for ordinals: ‘1’ as ‘1st’, ‘2’ as ‘2nd’ etc

Looks like you are looking for ordinalize: The Ruby on Rails framework is chock full of interesting little nuggets. Ordinalize is a number extension that returns the corresponding ordinal number as a string. For instance, 1.ordinalize returns “1st” and 22.ordinalize return “22nd”. Example: place = 3 puts “You are currently in #{place.ordinalize} place.” Result: You … Read more

How to write controller tests when you override devise registration controller?

The problem is that Devise is unable to map routes from the test back to the original controller. That means that while your app actually works fine if you open it in the browser, your controller tests will still fail. The solution is to add the devise mapping to the request before each test like … Read more

Mongoid / Mongodb and querying embedded documents

You can query embedded documents, just qualify the name. Now, this will return all Authors that have books that match your query. If Author is defined as having many :books (and book is an embedded::document) @authors_with_sewid = Author.where(“books.name” => “sewid”).all You’d then need to iterate over the authors and extract the books.

Where’s root_path or root_url?

These helpers exist, but you have to set your root url before, in config/routes.rb: root :to => “controller#action” You can use root_url and root_path afterwards. Be warned that there’s a catch when doing redirections with the _path helpers, you should use the _url ones when redirecting (see @LanguagesNamedAfterCoffee’s comment for the details).

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)