Ending a Rails 2 URL with an IP address causes routing error?
Route globbing worked!
My route is now:
map.connect 'find/by/*query', :controller => "find", :action => "by"
This puts everything following /find/by/ into an Array, params[:query], one URL segment per array object. For the query /find/by/ip/1.2.3.4, this looks like:
["ip", "1.2.3.4"]
So I can just refer to params[:query][0] and params[:query][1].
If anyone has a better way of doing it, please post it!
Routing Error No route matches [GET] /products/1
Looks like you are using Rails 7 since method: :delete
is no longer working without ujs
.
So, it leads to GET request and there is really no such route in your config.
This issue was discussed in this question and the solution is:
<%= link_to "Delete", product, data: { turbo-method: :delete, confirm: 'Are you sure?' } %>
But there is a catch: looks like not all versions of Rails 7 support this behavior. And this will not work inside the form because actual mechanics of changing the method is based on creating a hidden form. There is a discussion in the issue and a hint in the docs: you should use links only for GET
requests. For other requests use actual forms or buttons, so button_to will do the job better since it can change method and use confirmation prompt.
Rails 3.2 f.file_field causes routing error
Create passenger_extension.rb
in the lib
folder with this code:
Passenger 3
module PhusionPassenger
module Utils
protected
NULL = "\0".freeze
def split_by_null_into_hash(data)
args = data.split(NULL, -1)
args.pop
headers_hash = Hash.new
args.each_slice(2).to_a.each do |pair|
headers_hash[pair.first] = pair.last unless headers_hash.keys.include? pair.first
end
return headers_hash
end
end
end
Passenger 5
module PhusionPassenger
module Utils
# Utility functions that can potentially be accelerated by native_support functions.
module NativeSupportUtils
extend self
NULL = "\0".freeze
class ProcessTimes < Struct.new(:utime, :stime)
end
def split_by_null_into_hash(data)
args = data.split(NULL, -1)
args.pop
headers_hash = Hash.new
args.each_slice(2).to_a.each do |pair|
headers_hash[pair.first] = pair.last unless headers_hash.keys.include? pair.first
end
return headers_hash
end
def process_times
times = Process.times
return ProcessTimes.new((times.utime * 1_000_000).to_i,
(times.stime * 1_000_000).to_i)
end
end
end # module Utils
end # module PhusionPassenger
And then in 'config/application.rb' do:
class Application < Rails::Application
...
config.autoload_paths += %W(#{config.root}/lib)
require 'passenger_extension'
end
And then restart a webserver.
NOTICE: I'm not sure that this doesn't break any other functionality so use it on your own risk and please let me know if you find any harm from this approach.
issue with delete URL when using rails 4
Your generated HTML, routes, and controller all look good. It sounds like the proper js is enabled in your app and in your browser, but in your logs your request is a GET instead of a DELETE. This leads me to believe that you must have an error elsewhere in your javascript which is preventing all of the javascript on the page from executing. I recommend firebug for locating the error.
Not routes match with URL generation error
Here @profile is passing as nil, please check profile object , or you are trying to check story user profile then pass story.user inside
profile_path(story.user)
.
Routing error No route matches in non-resourceful route
In the end, I ended up solving this problem myself and feel a bit stupid about not seeing it earlier. I forgot that I had introduced a new layout used by the view in question. This layout included link_to order_path(@order) if @order
. This was the line that was, in fact, causing the error. @order
existed, but it had not yet been persisted, so @order.id
did not exist; this prevented it from matching the resourceful show route for @order
: order GET /orders/:id(.:format) orders#show
and causing the error. I fixed the problem by changing link_to order_path(@order) if @order
to link_to order_path(@order) if @order.id
.
Rails truncating of parameters with '.' in urls
You need to add a constraint to the routes to allow dots in params
resources :whitelists, :constraints => { :id => /[0-9.]+/ }
Or something of that kind in your routes.rb, it depends on how you write your routes but the constraints part stay the same
Why is the route not finding the the decimal
I would try
map.connect ... , :constraints => { :band => /.*/ }
(Or any other pattern of your taste.) About constraints
It doesn't seem to be working in all versions of rails, though. I'm pretty sure I used this trick before, but can't get it to work now. So, good luck with it.
Related Topics
Ruby on Rails - Is Params a Method or a Hash
List Dynamic Attributes in a Mongoid Model
Ruby Select and Reject in One Method
Sinatra and Session Variables Which Are Not Being Set
Rvm VS Native Installation of Ruby
How to Implement Options Hashes in Ruby
How to Escape a Single Quote in Ruby
Setting Environment Variables with Puppet
Unpacking/Freezing Gems into a Non-Rails Ruby App
Get Jekyll Configuration Inside Plugin
Convert HTML to Plain Text (With Inclusion of <Br>S)
Facebook Open Graph from Rails Heroku
Initializing Instance Variables in Mixins