Rails root url returns blank page - ruby-on-rails

When i'm trying to get mydomain.com it returns blank page with no errors.
I have the correct root in routes.rb and when I'm trying to get the page that must be root mydomain.com/root_page it works fine.
Any page of my site works fine
public/index.html is deleted.
what is the problem with this approach?
Thanks.
here is my routes.rb file
mydomain.com::Application.routes.draw do
get "admin/index"
match "admin" => "admin#index"
match "materialy" => "materials#indexall"
match "materialy/:id" => "materials#showall"
match "m/:id" => "materials#light"
match "nashi-raboti" => "ourworks#indexall"
match "nashi-raboti/:alias" => "wphotos#indexall"
match "galereja" => "gphotos#indexall"
scope "/admin" do
resources :gphotos, :materials, :posts, :mphotos, :titles
resources :ourworks do
resources :wphotos
end
end
match ":alias" => "posts#showall"
root :to => "posts#showall", :alias => "main"
end
so when im trying to get mydomain.com/main everything works fine.
Nothing is written to development.log when i'm truing to get mydomain.com, but everything is good when i'm trying to get mydomain.com/main or any other page.

"mydomain.com" it is your application name? I think the problem is due to this. Try create app without dot in name.

Related

Is it possible to have same routes with different show action in rails?

I am trying to reach the following url in my rails app:
example.com/user12 # It should show user#show
exmple.com/wordpress # It should show category#show
My solution: (it does not work)
In the routes.rb I have added :path => '' to both categories and users in order to remove the controllers' name from the url.
resources :categories, :path => ''
resources :users, :path => ''
When I run rake routes, I have the following urls"
category GET /:id(.:format) category#show
account GET /:id(.:format) accounts#show
So I assumed that It should be working correctly, but surely not. It only works for category names and for usernames it shows ActiveRecord::RecordNotFound.
I know, my solution is wrong because I am confusing rails route system and because the resources :categories has more priority over resources :users, the category show page works fine.
So Is there any solution to solve an issue like this?
I have finally found the solution with constraints option. This option accepts regular expressions.
resources :categories, :path => '', constraints: { id: /wordpress|php/ }
Every category should be added manually in this way OR (I am not sure) maybe there is a way to list all categories from database automatically.
One way of doing that is to override the default rails routes, to do that remove the resources
I tested and this works
SampleRails4::Application.routes.draw do
get '/user12', to: 'users#show' #=> users/show
get '/wordpress', to: 'category#show' #=> assuming u have a controller and action
end
however then you have to update the rest of your code, Ex: users/show might be expecting the user id as a param read more about rails routing

Rails 4: You should not use the `match` method in your router without specifying an HTTP method

Okay, so I've upgraded to Rails 4 (kind of unplanned with my 10.9 server update) and have been able to get everything running on my photo gallery app except for the routes. For some reason I've always had trouble understanding routes since rails 3. Here was my previous working code under Rails 3
root :to => "gallery#index", :as => "gallery"
get 'gallery' => 'gallery#index'
resources :galleries
match 'gallery_:id' => 'gallery#show', :as => 'gallery'
I understand that match has been depreciated, but if I try to use GET, I'm getting the following error:
Invalid route name, already in use: 'gallery' You may have defined two routes with the same name using the :as option, or you may be overriding a route already defined by a resource with the same naming.
Basically, I want the root (index) to load as "/photos/gallery" as it does, and my show action to load, for example, record id 435 as: "/photos/gallery_435" which is how I previously had it working. Sorry for what is probably a simple question, I just cannot seem to grasp the rails routing.
Try this
match 'gallery_:id' => 'gallery#show', :via => [:get], :as => 'gallery_show'
You can then refer to this path as gallery_show_path in your helpers and views.
Changing the 'as' removes the conflict.

Rails 3 add new routes to resources

I have the following problem:
I created one entity "Film" with the command "scaffold" and automatically added in my routes file "resources: films", and then I try to added an autocomplete via ajax, but always the calling ajax calls the "show" action instead of call the route that I added "autocomplete_term"
My routes files (routes.rb)
resources :films
I tried the following possibilities (routes.rb)
match 'films/autocomplete_term' => "films#index", :via=>:get
match "films/autocomplete_term/:term" => "films#autocomplete_term", :controller=>"films", :action=>"autocomplete_term", :as => :films_autocomplete, :via => :get
resources :films do
collection do
get 'autocomplete_term'
end
end
The route
** localhost.com:3000/films/autocomplete_term?term=a**
The ERROR
Couldn't find Film with id=autocomplete_term
app/controllers/films_controller.rb:28:in `show'
When I run the command rake routes
GET /films/autocomplete_term/:term(.:format) films#autocomplete_term
films_autocomplete
GET /films/autocomplete_term/:term(.:format) films#autocomplete_term
autocomplete_term_films
GET /films/autocomplete_term(.:format) films#autocomplete_term
Sorry for my English
And thanks in advance
The url to access this route
GET /films/autocomplete_term/:term
should be
localhost.com:3000/films/autocomplete_term/a
if you do localhost.com:3000/films/autocomplete_term?term=a it will think it is the show action, it will ignore the ?term=a
GET /films/:id
Thanks to Anezio, solved the problem, basicament had two things wrong:
1 - The route
match "films / autocomplete_term /: term"
2: The order in my routes.rb file (Rails routes are matched in the order they are specified)
resources: films
match 'films / autocomplete_term /: term' => "films # autocomplete_term"
The Final Solution: (routes.rb)
match 'films / autocomplete_term' => "films # autocomplete_term"
resources: films

Rails 3 path parameters not part of params

I'm trying to upgrade a Rails 2 app to Rails 3, and I'm really having problems with a route. Here's what I have in the routes.rb file
get 'profile/:login' => 'account#profile', :as => :profile
When I go to http://localhost:3000/profile/MyUsername, it does not correctly add :login to the params hash. See here:
Started GET "/profile/MyUsername?foo=bar" for 127.0.0.1 at Tue Mar 20 21:39:03 -0400 2012
Processing by AccountController#profile as HTML
Parameters: {"foo"=>"bar"}
For some reason, :login is not part of the regular params. On a hunch, I inspected the request.env and found this:
action_dispatch.request.path_parameters"=>{:action=>"profile", :controller=>"account", :login=>"MyUsername"}
I'm totally stumped at this point. Am I missing something? Where should I look next to figure out what is going on here?
Update
I started playing with removing gems and this magically worked. I just commented out gems from the Gemfile until I got the absolute minimal set needed to load the homepage. At that point, the params were exactly as expected. Then I added gems back a few at a time in order to find the cause. I added everything back and...it works now. Crazy, but whatever it takes, I guess.
Looks like you mixed the syntax for 'match' with 'get'. Please try:
match 'profile/:login' => 'account#profile', :as => :profile, :via => :get
Or
get 'profile/:login', :to => 'account#profile', :as => :profile
in your config/routes.rb
When I want to use URL params I always use resource(s) when defining the route. That is convention with Rails 3.x so you can try it.
resources :accounts , :exclude => :all do
member do
get :profile
end
end
This should help or any other way of defining resource URL.
Something like this should work
match 'profile(/:login)' => "account#profile", :as => :profile
If it does not, there may be something else in your routes file that conflicts. Make sure any match ':controller(/:action(/:id(.:format)))' (or similar "match everything" routes) are at the very bottom of your routes file.

Rails 3 - changing index

I'm using Rails 3 and have the feeling that the syntax for changing the route for the index (http://localhost:3000) is different than from the former versions.
I'd like to open the dynamic index page (index.html.erb) of the employees-controller (which can be right now opened with localhost:3000/employees) as the default page (localhost:3000). I thought it's quite easy, because in the routes it's written:
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"
So that's what I actually did: I deleted public/index.html and set root :to => "employees#index".
But when I open the server and open localhost:3000, it's still opening the "welcome abroad!"-page. Pretty weird!
So I googled the problem and found answers which said, I should write this into my routes-file:
map.root :controller => 'employees', :action => 'index'
Same here - I also still get the "welcome abroad!"-page and the rails-shell says "undefined local variable or method 'map'". (I think this is the old syntax for Rails 2...?)
match "/" => "employees#index" says routing error: No route matches "/"
So what did I do wrong? How can I solve this problem?
Why you use "map" in Rails 3? Should be:
root :to => "employees#index"
I think problem is of cookies. please clear the cookies and the refresh the page.

Resources