der_tom
(der_tom)
March 5, 2018, 5:13pm
1
HI,
i have a couple of ‘seo’ routes, which are not responding well
eg:
match ‘whatever/in/:seoterm’ , as: 'seo_whatever
_in’ , :to => ‘foos#index’, via: [:get] , :mode=>{:x=>’
whatever
',:y=>1}
respond_to do |format|
format.html {
}
format.js {
}
format.json {
render :json => JSON::parse({:list => @… }
}
format.xml {
#render xml: @person.to_xml (include: @company )
render xml: @commutes.to_xml #(include: @company )
}
end
→ the only thing i see is that the brwoser comes as / , which shouldnt be the problem:
Started GET “/whatever/in/St.%20Peters” for 10.0.1.37 at 2018-03-05 12:09:39 -0500
Processing by FooController#index as
any ideas?
thx
hassan
(Hassan Schroeder)
March 5, 2018, 5:29pm
2
der_tom
(der_tom)
March 5, 2018, 5:33pm
3
getting 406 due to rails giving me ActionController::UnknownFormat
and i dont know why.
same routes(pattern) in a different controller work just fine. only difference is that the other one only does render, not repsond_to
hassan
(Hassan Schroeder)
March 5, 2018, 5:53pm
4
getting 406 due to rails giving me ActionController::UnknownFormat
and i dont know why.
Maybe because GET "/whatever/in/St.%20Peters" provides no
information about the requested response format?
same routes(pattern) in a different controller work just fine. only
difference is that the other one only does render, not repsond_to
I'd think that would be a good clue...
der_tom
(der_tom)
March 5, 2018, 5:59pm
5
so how can i pass this along? why is it not assuming html?
hassan
(Hassan Schroeder)
March 5, 2018, 6:15pm
6
Because computers don't make assumptions?
Why are you telling it to respond differently depending on the format
and then *not providing a format*??
der_tom
(der_tom)
March 5, 2018, 6:27pm
7
, :defaults => { :format => ‘html’ }
fixed it
thank you
so how can i pass this along? why is it not assuming html?
Because computers don’t make assumptions?
Why are you telling it to respond differently depending on the format
and then not providing a format ??
–
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote
Started GET “/whatever/in/St.%20Peters” for 10.0.1.37 at 2018-03-05 12:09:39 -0500
Processing by FooController#index as
You really should have added one more line from the log here.
It was very likely looking for a :format => '%20Peters" because of the ‘.’ in the URL path.
Look at the output from rails routes
to see the various ways that you might be routing to foos#index
Another way to fix this tends to “break” having multiple formats. You can add:
eg:
match ‘whatever/in/:seoterm’ , as: ‘seo_whatever _in’ , :to => ‘foos#index’, via: [:get] , :mode=>{:x=>’ whatever ',:y=>1}
, constraints: { seoterm: /.+/ }
so that :seoterm slurps all the remaining characters of the URL. This breaks the “implicit” (.:format) that gets added because the constraint will match the ‘.’ and everything after it leaving nothing to match the “optional” format.
-Rob
der_tom
(der_tom)
March 5, 2018, 9:12pm
10
you are correct. the space and or the period was the problem here.
ill try out different solutions now
thx all!