Resque-web path not working - ruby-on-rails

I just upgraded to rails 3.1 and is getting a weird routing problem with resque-web
I've mounted resque-web on my routing.rb like this:
mount Resque::Server, :at => "/resque"
when my server is up going to 0.0.0.0:5000/resque works fine but declaring the path 'resque_path' in my erb.html files gives me
undefined local variable or method `resque_path' for #<#<Class:0x000001038e9eb0>:0x000001038a7650>
it's even listed on my rake routes as:
resque_server /resque {:to=>Resque::Server}
'resque_path' should be working! i hav no idea why it is now. anyone?

If you check rake routes you can see that solution is:
resque_web_path

Have you tried resque_server_path? That could do it.

Related

Rails Tutorial sample_app fails in Heroku with log: ActionController::RoutingError (No route matches [GET] "/about"):

I am following the online version of Rails Tutorial. The Sample_app in chapter 3 works fine locally, but when pushed to Heroku, the home page is found but not the other pages. Running heroku logs after trying to see the About page gives me (along with much else) the error above:
2015-08-09T02:56:43.916991+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/about"):
My routes.rb file is
Rails.application.routes.draw do
root 'static_pages#home'
get 'static_pages/help'
get 'static_pages/about'
end
I have followed the directions carefully. I tried deleting and recreating the Heroku file. I did web searches and tried some things to no avail. My gemfile is straight from the online version of the book, which is using current versions.
Solved: #thedanotto had me run heroku run rake routes which showed that the help and about pages were directed to {root}/static_pages/about rather than {root}/about. I am still puzzled why the tutorial gives the about routes, which appear not to work as expected, and welcome any further comment, but I am marking this as solved.
Whenever I can't find a route, I run the terminal command
rake routes
Since you're on heroku you'll want to run
heroku run rake routes
Which will return something similar to the following.
Prefix Verb URI Pattern Controller#Action
static_pages_about GET /static_pages/about(.:format) static_pages#about
So that shows that you can go to www.[heroku_app_name].herokuapp.com/static_pages/about And it will bring you to the page you want. You can also add a link to the page in a view by putting the following line of code within a view.
<%= link_to("About", static_pages_about_path) %>
That's all good stuff to know. But let's talk about using the controller action: static_pages#about with the path /about
Switch the following in routes.rb from
get 'static_pages/about'
to
get "static_pages/about", path:"/about"
or alternatively
get "/about", to: "rabbits#about"
You can read more about Routes here
If it works fine locally, I assume you've set up the controllers, views etc properly.
Have you made sure to commit all those necessary changes then push?
e.g.
git add .
git commit -am "Added route"
git push heroku master
Are you accessing the about page using the following URL ?
http://YourHerokuAppName.herokuapp.com/static_pages/about
[ Replace "YourHerokuAppName" with your Heroku App Name]

rails beginner, created 2 rails app on local dev

I am new to rails and I was able to install rails (3.2.3, ruby v1.9.3), then created a test app:
$ rails new Hello
then I cd'd into the new directory 'hello' and did the following commands:
$ rails generate controller home index
$ rails s
$ rake routes, it gave me
home_index GET /home/index(.:format) home#index
hello /hello(.:format) Hello#index
Then I pointed my browser to: http://localhost:3000/home/index - and it worked great.
Then I wanted to begin a tutorial and it asked me to create a new rails application
so I did like I did before...
$ rails new TutorialApp
$ rails generate controller tutorial index
$ rails s
$ rake routes, it gave me
tutorial_index GET /tutorial/index(.:format) tutorial#index
then I pointed my browser to: http://localhost:3000/tutorial/index, it gave me a message of
Routing Error
No route matches [GET] "/tutorial/index" Try running rake routes for
more information on available routes.
So I ran rake routes again, which it gave me the same output as it did before
tutorial_index GET /tutorial/index(.:format) tutorial#index
Since I created that first rails app "Hello", do I need to turn off that app before starting the new rails app "Tutorial" or they can both be running at the same time?
Any help is appreciated, thanks!
You can use a different port
rails server -p 3001
It will run in a different port. Then, just point to http://localhost:3001
But usually you will probably stop the server on one app and start the other one. It's up to you.
When you run rails server ("rails s"), you're typically running it in the context of the rails project you're in at the time, so before beginning a new project, I would shut down the current server (CTRL C). Also, make sure you create a new rails app in a folder is isn't itself at the root of a rails app. It looks like you might have created your tutorial app inside the root of your Hello app. Sounds like those are the two main things that tripped you up.

Why is url_for returning /assets for undefined routes?

I'm upgrading from rails 3.1.3 to 3.2.2, but for some reason now url_for always returns /assets if the route doesn't exist.
For example:
url_for({}) #=> "/assets"
url_for({action: 'fake', controller: 'notreal'}) #=> /assets?action=fake&controller=notreal
But I want it to to throw the normal ActionController::RoutingError as it normally does...
Rails does not check for route existence if you build up the route via specifying controller-action. And naturally it shows /assets for {} route.
You should better specify named routes in routes.rb and then use them for url_for. Like:
url_for add_user_path
This ensures you will either succeed (for existent named route) or get an error.
HTH
I think you have assets pre-compilation on and since the image does not exist in the assets folder, the compile file name is null but the path points to the root of the assets folder. Are you also be seeing an error about not finding the pre-compiled asset in the logs?
Try running without assets pre-compilation in the development environment to get past this. I will not rehash details on assets precompilation - you can check http://guides.rubyonrails.org/asset_pipeline.html for details on asset pipeline. If you are seeing this issue only in production environment, it might be because the host platform is precompiling the assets for you.
However, if you expect this to happen in production, you might want to check for the presence of the image instead of disabling precompilation.

Ruby on Rails index.html.erb not loading

Just starting in Rails and I'm trying to get my index.html.erb page to show when I enter my rails-backend sub-domain.
I've been following the instructions from this guide but have run into some trouble. Searching google and SO for an answer did not yield results, so here I am.
I ran $ rails generate controller home index in order to generate index.html.erb, and deleted public/index.html as well. I then went to the routes.rb file in the /config directory and added this line:
root :to => 'home#index'
I also removed this line:
get "home/index"
My index.html.erb in the app/views/home/ directory looks like this:
<h1>Hello Rails, my best friend!</h1>
<p>Find me in app/views/home/index.html.erb</p>
<br />
<p>Also word to your mother</p>
I ran rake routes in the terminal and got this output:
(in var/www/testapp)
root / home#index
When I try to go to my sub-domain I get the following page:
I then tried uncommenting the get "home/index" line in routes.rb, but the same result showed up. Here is my home_controller.rb file, which I didn't touch but a) the guide didn't ask me to and b) looks normal compared to other controllers I've seen:
class HomeController < ApplicationController
def index
end
end
I'm sure this is a simple question, but I couldn't find any questions with a similar situation on SO. Thanks for helping!
Your code all looks correct. I would recommend foregoing Passenger and use the Thin server instead. It handles both http and https.
It's as simple as this:
Add the following line to your Gemfile: gem 'thin'
Install the gem: bundle
Start the server: bundle exec thin start --ssl
This way, you receive the benefits of the Mongrel parser and SSL without needing any custom Apache configuration.

Nesta CMS and Rails3 integration: adding blog to an exiting rails 3 application

I'm adding nesta (0.9.8) cms, to an existing Rails 3.0.10 application. I get the blog up and running but not the layout/stylesheets.
What i did until now is :
1. inside rails app main root, add gem 'nesta', gem 'sass' and run
'bundle'
2. run "nesta new nesta-blog"
3. edit config.ru like following :
require ::File.expand_path('../config/environment', __FILE__)
map "/" do
run MyRails3App::Application
end
require 'nesta/env'
require 'nesta/app'
Nesta::App.root = ::File.expand_path('./nesta-blog', ::File.dirname(__FILE__))
map "/blog" do
run Nesta::App
end
4. edit config/routes.rb like following :
require 'nesta/env'
require 'nesta/app'
Rails3MongoidOmniauthSimple::Application.routes.draw do
mount Nesta::App.new => "/blog"
root :to => "home#index"
...
5. cd nesta-blog
6. run nesta demo:content
Now, if you run rails s from your ~/main-rails-app, going to http://localhost:3000/blog you will see the the demo nesta site but without his default layout/stylesheets, while if you run shotgun config.ru from inside ~/main-rails-app/nesta-blog, going to http://localhost:9393/ everything shows up correctly.
Any suggestion?
Thanks in advance
Luca G. Soave
I've not got this to the level of plug-n-play that I'd like yet, but I'm running Nesta on my Rails 3.0 sites by adding this to config/routes.rb:
mount Nesta::App, :at => '/'
match '/css/*style.css' => Nesta::App
match '/attachments/*file' => Nesta::App
I haven't looked into a cleaner way of doing this yet (i.e. avoiding having to specify css and attachments routes as well).
I created my Nesta app in a directory located at "#{Rails.root}/nesta". I also needed an in config/initializers/nesta.rb:
require "nesta/env"
Nesta::Env.root = ::File.expand_path("../../nesta",
File.dirname(__FILE__))
I quite like the way you've done it too.

Resources