i'm trying to use the jQuery Uploadify on a Ruby on Rails project. i am able to browse for a file, and select it. the upload progress goes till 100% and then i get a HTTP error. my development.log is below
Processing ApplicationController#index (for 127.0.0.1 at 2010-02-07 18:33:01) [POST]
Parameters: {"Filename"=>"file.psd", "folder"=>"/uploads", "Upload"=>"Submit Query", "Filedata"=>#<File:/var/folders/j5/j5kRE9LqGzqgPWZPtCoi1k+++TI/-Tmp-/RackMultipart20100207-1470-c8y8uc-0>}
ActionController::RoutingError (No route matches "/javascripts/uploadify.php" with {:method=>:post}):
Rendering rescues/layout (not_found)
Anyone knows what's wrong here?
I believe your form action is very wrong - you're using Ruby On Rails, but action submits form to php file.
My guess is you probably have the default catchall routes in your routes.rb file:
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
Remove those lines and it should work.
See this excellent guide for all you need to know about Rails Routes.
Related
I am learning how to login from Rails and I wanted to know one thing:
I have several files which I want to show when a certain condition is met, in this case logging in will redirect me to another file called starter.html.erb
I am trying to redirect it through both the controller and the routes files and I get the following error:
No route matches [GET] "/app/views/usuarios/starter.html.erb"
Can you please tell me what I'm doing wrong? Thanks!
Controller portion:
redirect_to search_starter_path
routes.rb portion:
get "/search/starter" => redirect("/app/views/usuarios/starter.html.erb")
You have to use the controller#action syntax to redirect. Example: if your controller is usuarios_controller.rb you should have inside an action named starter. Then in your routes.rb put this entry:
get "search/starter" => 'usuarios#starter'
I have a rails link that's using the POST method:
link_to "Run", forecast_run_path(#forecast), method: :post
to call a defined post route:
resources :forecasts do
post :run
end
The route appears in rake routes output as expected:
forecast_run POST /forecasts/:forecast_id/run(.:format) forecasts#run
And when I inspect the page, the expected post link appears in the page:
Run Forecast
In dev it works fine, and was good in production until sometime just a few days ago - I can't find any change that seems like it should have broken it. But when I click the link, I get the error ActionController::RoutingError (No route matches [GET] "/forecasts/20/run")
I agree that no GET route matches, but it should be using POST.
This is Ruby 2.1.5, Rails 4.2.0
To my own embarrassment and for the benefit of anyone else who has the same issue:
As I switched among different clients, I didn't notice that on one of them NoScript in Firefox was blocking javascript on that site. Doh!
When you post a run, the form will direct you to the show action where it displays the newly posted run, in your case you don't have a show action for run, so implement a show action and should work fine.
I am working a basic rails miniblog tutorial that is based on an older rails (dunno if that is the problem). I am trying to implement user logout (terminate a user session).
I have this in my form:
<%= link_to 'Logout', session_path(current_user), method: :delete %>
and my rake routes table looks good:
session DELETE /sessions/:id(.:format) sessions#destroy
but when I test it on local server, by clicking on 'Logout', I was given this error:
No route matches [GET] "/sessions/1"
It really should not have been a [GET] request. I checked that I included all the necessary javascript lines and bundle. What went wrong?
p.s. here is my repo: https://github.com/lukexuanliu/CornellBlog
p.p.s. my problem is very similar to this one: Routing Error No route matches [GET] "/microposts/304 - Deleting a Micropost - Michael Hartl's railstutorial.org Chapter 11
but their solution does not work for me. also, my bootstrap css is kind of messed up... dunno if that contributed to the problem
I think I found the problem. When I said "by clicking on Logout," I actually pull out the html code (using inspect element) to click on the actual code "session/1" which will mistakenly issue a [GET] request. as I clean up my stylesheets (turns out to be incompatibility of bootstrap2 code running on bootstrap3 api) and revealed the Logout button to click on, it works fine. curious.
I scoured my app's directories, and I can't find the html page for the default rails Welcome Aboard page. I also cannot find a route for the default Welcome Aboard page in routes.rb. How does my rails app route http://localhost:3000/ to a non-existent page in my app?
The rails server produces this information:
Started GET "/" for 127.0.0.1 at 2013-07-31 02:00:13 -0600
Processing by Rails::WelcomeController#index as HTML
Rendered /Users/7stud/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/templates/rails/welcome/index.html.erb (0.1ms)
Completed 200 OK in 3ms (Views: 2.5ms | ActiveRecord: 0.0ms)
So it looks to me like there is a controller buried in a gem somewhere that handles the request.
Since Rails 4, the "Welcome aboard" page is no longer located in public/index.html. It is - as you've already detected - located inside one of the Rails gems.
So you already answered the question yourself; the "Welcome aboard" page is - in your case - located at /Users/7stud/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/templates/rails/welcome/index.html.erb
To get rid of it, following the instructions on the page. Basically they are:
Create a controller
Add a root route in config/routes.rb to route to that newly created controller.
As for how the request to your application ends up at a controller inside railties, let's dig into the gem: Inside Rails::Application::Finisher we find this:
initializer :add_builtin_route do |app|
if Rails.env.development?
app.routes.append do
get '/rails/info/properties' => "rails/info#properties"
get '/rails/info/routes' => "rails/info#routes"
get '/rails/info' => "rails/info#index"
get '/' => "rails/welcome#index"
end
end
end
This block adds a few routes to your application when running in development mode - one of those is the route to the "Welcome aboard" action: get '/' => "rails/welcome#index"
This - like any other initializer - is done when your start your application server (running rails server or however you do it). In the case of Finisher, all its initializer are run after all other initializers are run.
Note how the routes are appended so that they are appear last in the Routeset. This, combined with the fact that Rails uses the first matching route it finds, ensures those default routes will only get used if no other route is defined.
Warp Drive is a nice way to package an entire Rails application into a Gem for use in other Rails applications. I've gotten Warp Drive to work for a blogging engine I'm creating. There's just one problem - Authlogic OpenID authentication fails.
I created a bare-bones OpenID example application. I can compile to a gem with no problems:
$ warpify
$ rake warp_drive:compile
I then installed the compiled gem on my system. Creating a blank Rails project, I ran:
$ install_warp_drive rails-openid
You can get this project here.
In my blank Rails projects, I needed to configure gems through environment.rb (I'm probably doing this the wrong way):
config.gem "authlogic"
config.gem "authlogic-oid", :lib => "authlogic_openid"
config.gem "ruby-openid", :lib => "openid"
To get the blank Rails application working, I ran rake db:migrate, then through the console I added a user with an :openid_identifier field set to one that I control. So far so good. But trying to create a new session fails with this error:
Processing UserSessionsController#create (for 127.0.0.1 at 2009-12-31 11:35:59) [POST]
Parameters: {"commit"=>"Login", "user_session"=>{"openid_identifier"=>"richdev.myopenid.com"}, "authenticity_token"=>"BcsIKNpumqZrTV/bdSLQ6szBvq6kpaAIxJRmYgxySLU="}
OpenIdAuthentication::Association Load (0.3ms) SELECT * FROM "open_id_authentication_associations" WHERE ("open_id_authentication_associations"."server_url" = 'http://www.myopenid.com/server')
Generated checkid_setup request to http://www.myopenid.com/server with assocication {HMAC-SHA1}{4b3cf228}{mWlzhg==}
Redirected to http://www.myopenid.com/server?openid.assoc_handle=%7BHMAC-SHA1%7D%7B4b3cf228%7D%7BmWlzhg%3D%3D%7D&openid.ax.mode=fetch_request&openid.identity=http%3A%2F%2Frichdev.myopenid.com%2F&openid.mode=checkid_setup&openid.return_to=http%3A%2F%2Flocalhost%3A3001%2Fuser_sessions%2Fcreate%3Ffor_session%3D1%26_method%3Dpost%26open_id_complete%3D1%26openid1_claimed_id%3Dhttp%253A%252F%252Frichdev.myopenid.com%252F%26rp_nonce%3D2009-12-31T19%253A35%253A59ZUEd2eN&openid.trust_root=http%3A%2F%2Flocalhost%3A3001%2F
Completed in 15ms (DB: 0) | 302 Found [http://localhost/user_sessions]
Processing ApplicationController#index (for 127.0.0.1 at 2009-12-31 11:36:00) [POST]
Parameters: {"openid.mode"=>"id_res", "openid.return_to"=>"http://localhost:3001/user_sessions/create?for_session=1&_method=post&open_id_complete=1&openid1_claimed_id=http%3A%2F%2Frichdev.myopenid.com%2F&rp_nonce=2009-12-31T19%3A35%3A59ZUEd2eN", "openid.sig"=>"l+tfFAmeKsskHKlOYRoZF7yHM7Q=", "rp_nonce"=>"2009-12-31T19:35:59ZUEd2eN", "openid.op_endpoint"=>"http://www.myopenid.com/server", "for_session"=>"1", "openid.response_nonce"=>"2009-12-31T19:36:00ZBhX5fE", "openid1_claimed_id"=>"http://richdev.myopenid.com/", "openid.identity"=>"http://richdev.myopenid.com/", "open_id_complete"=>"1", "openid.assoc_handle"=>"{HMAC-SHA1}{4b3cf228}{mWlzhg==}", "openid.signed"=>"assoc_handle,identity,mode,op_endpoint,response_nonce,return_to,signed"}
ActionController::MethodNotAllowed (Only get, put, and delete requests are allowed.):
Rendered rescues/_trace (96.3ms)
Rendered rescues/_request_and_response (0.5ms)
Rendering rescues/layout (method_not_allowed)
The problem seems to occur during the redirect back from the openid provider, at which point ApplicationController#index gets called, instead of UserSessionsController#create. I'm not sure if this is an OpenID issue or a Warp Drive issue.
How can I bundle an Authlogic/OpenID application as a Warp Drive Gem and get authentication to work successfully?
Update: Adding an explicit resource definition for user_session fixes the problem. In routes.rb:
map.resources :user_sessions
Not sure why, and this doesn't seem to be required for any other controller.
Two things worked:
Add an explicit user_session resource definition in routes.rb:
map.resources :user_sessions
Remove default routes in routes.rb of the app using the warp drive gem.
Removing default routes in routes.rb
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
solved a horrific routing issue where a resource routing in the warp drive:
map.resources :users, :member => {:activate => [:post, :get]}
created a URL: /users/:id/activate(.:format)
But an HTTP request to that URL resulted in the :action and :id getting reversed when passed to the controller (as if interpreted as a default URL). e.g.
Parameters = {"action"=>"123456", "id"=>"activate", "controller"=>"users"}
Not pretty. Removing the default routes in the warp drive or the client app did it. Seems safer to do it in the client app, though.