I have gem 'rspec-rails', '~> 2.14.2' in my Gemfile.
After upgrading from Rails 4.1 to Rails 4.2 I've got the following error while running rspec:
Failure/Error: get 'api/...'
URI::InvalidURIError:
the scheme http does not accept registry part: www.example.com:80api (or bad hostname?)
What's the fix?
Adding / to a path fixes the issue.
E.g.:
get 'api/...' => get '/api/...'
post 'api/...' => post '/api/...'
patch 'api/...' => patch '/api/...'
put 'api/...' => put '/api/...'
etc.
EDIT: the reason is explained here.
Related
I am learning to use haml in rails 4.
I added this line to my 'demo/index.html.haml' file:
= link_to 'Hello with parameters',:controller => 'demo', :action => 'hello', :id=> 21, :page => 5
The resulting html output is missing a slash between the string hello and 21 like this:
Hello with parameters
I am not sure why the forward slash is missing.
My Gemfile has this:
gem 'haml-rails'
Please tell me if I can provide more information to help troubleshoot this.
I am running:
windows 7
ruby 2.1.5p273 (2014-11-13 revision 48405) [i386-mingw32]
Rails 4.2.2
haml (4.0.7)
haml-rails (0.9.0)
html2haml (2.0.0)
Thank you in advance.
EDIT
I was asked about my route.rb:
Rails.application.routes.draw do
root 'demo#index'
# Default Route
match ':controller(/:action(:id(.:format)))', :via => :get
end
And when I run rake routes I get:
$ rake routes
DL is deprecated, please use Fiddle
Prefix Verb URI Pattern Controller#Action
root GET / demo#index
GET /:controller(/:action(:id(.:format))) :controller#:action
The slash is already missing in your route. Add it after :action like so:
match ':controller(/:action/(:id(.:format)))', :via => :get
I am trying to port a working rails 2.4 app to rails 4.2. I cannot get the routing to work.
the URL of x.pdf is broken into id.format and passed as params to a report controller.
in Rails 2.4 I have
map.report ':id.:format', :controller => :reports, :action => :generate
in Rails 4.2 I am trying to use
get ':id.:format' => 'reports#generate'
but when i run the app and browse to http://www.example.com/x.pdf, i get the fatal error
ActionController::RoutingError (No route matches [GET] "/x"):
When I run rake routes I get:
Prefix Verb URI Pattern Controller#Action
GET /:id.:format reports#generate
I am using Ruby 2.3.0, Rails 4.2.5, NGINX 1.9.9, Passenger 5.0.23
Any help would be appreciated!
You should change get ':id.:format' to just get ':id'
We are upgrading from Rails 4.2.5 to 5.0.0.beta1
When testing we expected to see index views rendered with paginated links as before.
But we now get an ArgumentError error page, for example:
ArgumentError in Transactions#index
/app/views/kaminari/_paginator.html.erb where line #10 raised:
<%= paginator.render do -%>
Generating an URL from non sanitized request parameters is insecure!
Application Trace | Framework Trace | Full Trace
app/views/kaminari/_paginator.html.erb:10:in block in _app_views_kaminari__paginator_html_erb___4026289994022119719_69904100316060' app/views/kaminari/_paginator.html.erb:9:in_app_views_kaminari__paginator_html_erb___4026289994022119719_69904100316060'
app/views/transactions/index.html.erb:2:in `_app_views_transactions_index_html_erb__422882858554400818_60602560'
An issue has been raised with kaminari
On further investigation here is the new Rails 5.0.0.beta1 code that now throws the error:
Adding this to config/application.rb 'fixes' it, but not a great idea:
config.action_controller.permit_all_parameters = true
Instead adding this does not fix the issue, not sure why:
config.action_controller.always_permitted_parameters = [:current_page, :page, :total_pages, :per_page, :remote, :paginator]
This appears to be fixed in the github master branch, so for now in your gem file specify:
gem 'kaminari', :git => "git://github.com/amatsuda/kaminari.git", :branch => 'master'
I am beginner in Rails & MVC development, and need help with the below:
I am doing the example in http://edgeguides.rubyonrails.org/getting_started.html
In "5.12 Updating Posts", we are asked to add the following to our config/routes.rb:
patch "posts/:id" => "posts#update"
If I do that, and run rake routes, I am getting the below error:
undefined method `patch' for #<ActionDispatch::Routing::Mapper:0x390f078>
I get the same error when I go to - http://localhost:3000/posts/1
This is the line in edit.html.erb :
<%= form_for :post, url: { action: :update, id: #post.id }, method: :patch do |f| %>
I have Rails 3.2.1.
Environment:
I am doing this in Windows 7. I installed Rails via railsinstaller.org. Browsers - Chrome, Firefox
patch is only available in Rails master branch.
Here is the related pull request: https://github.com/rails/rails/issues/348
Here is the blog article explaining the reasoning: http://weblog.rubyonrails.org/2012/2/25/edge-rails-patch-is-the-new-primary-http-method-for-updates/
Here is another great summary: http://blog.remarkablelabs.com/2012/12/http-patch-verb-rails-4-countdown-to-2013
Among other things, you need to point to the git repo in your Gemfile to use edge rails on an already-existing project.
gem 'rails', :git => 'git://github.com/rails/rails.git'
For now you should just use PUT instead of PATCH. Even when 4.0 comes out, PUT isn't going anywhere.
fwiw, I backported the HTTP PATCH verb work for Rails 3.2 https://gist.github.com/bf4/8940203
I've been at this for awhile. I've tried using net http to connect to a https url with no luck. I've tried http party and getting uninitialized constant httpparty. I am running rails 3.2.7. I have httpparty add to gem file.
Can someone please provide an example with either problem sending params to a https url and receiving a response.
code:
options = {:id => params[:id], :code => params[:code]}
response = HTTPParty.post('https://test.com', options)
gem file:
gem "httparty", "~> 0.9.0"
HTTParty.get('https://google.com', :query => {:q => 'stack overflow'})
If this doesn't work for you, please show the code you're using. It you're getting an uninitialized constant error, you've done something wrong. Did you run bundle after adding to your Gemfile?
Also, it's HTTParty, not HTTPParty.