I have upgraded my localhost version of ruby from 1.8.7 to 1.9.2 and I got some errors in my templates.
For example, in ruby 1.8.7 I use following:
<%= link_to ((image_tag 'image.png', :alt => 'bla bla bal'),
url_for(root_url), :id => 'identifier')%>
This works me fine on ruby 1.8.7, but if I switch to ruby 1.9.2, I'll get this error:
syntax error, unexpected ',', expecting ')'
url_for(root_url), :id => 'identifier'));#output_buffer.safe_concat('
What is here for a problem? And could anyone help me, please, how to fix it?
ok, so it looks the only right answer it <%= link_to image_tag('image.png', :alt => 'bla bla bal'), root_url, :id => 'identifier'%>. It works on the both versions, 1.8.7 and 1.9.2
Related
I have recently upgraded a project to Rails 3.2 from 3.1 and have been stuck trying to figure out why the routing is not playing nicely with devise.
NoMethodError - undefined method `locale' for #<ActionDispatch::Request:xxxxx>:
This is on the new (1)Journey routing engine. The issue for now is with Devise only other modules are not erroring. I can tell the issue is within my use of scope. It works if I get ready of the scope.
scope "(:locale)", :locale => /#{I18n.available_locales.join("|")}/ do
devise_for :users, :controllers => { :registrations => "users/registrations" }
...
end
(1) Line 7 (133). Please see trace and Journey line error in context here.
Any advice and guidance is appreciated. Thank you.
Rails 3.2, Ruby 1.9.3
Try to put :locale in a :constraints hash:
scope "(:locale)", :constraints => {:locale => /#{I18n.available_locales.join("|")}/}
I think it will help for more problems too: http://guides.rubyonrails.org/routing.html
I'm using carrierwave and fog to upload files in my app. I upgraded all my gems and now receive this error wrong number of arguments (2 for 1)
<%= link_to image_tag(listing.image_url(:thumb).to_s,
:class => 'popup-image'),
listing,
:class => 'big-image-link' if listing.image? %>
Any idea what's wrong?
I just reverted back to fog version 1.3 and it worked again.
I have a link_to in a partial that generates a different URL when the page is accessed as the root then if it is accessed using controller/index. When accessed as the root, the URL the link_to generates has "assets" prefixed to it, which doesn't work.
Can anyone explain why this happens?
Rails 3.2.1
Ruby 1.9.3
With some help from the Rails IRC channel, I found the problem. I was not using the helper paths in the link. In case it will help someone else, here is what I did to fix it;
not working when at the root;
<%= link_to 'Gifts detail', :controller => 'gifts', :action => 'index'%>
working anytime;
<%= link_to 'Gifts detail', gifts_path%>
I'm quite new to RoR and programmed a couple of things before discovering Test-Driven-Development. So I tried to write some tests with guard-rspec and capybara. All was fine, but I got some deprecation warnings for devise (had version 1.1.rc02), so I updated it (now having latest version 1.4.5).
These were the warnings:
Running all specs
DEPRECATION WARNING: Using form_for(:name, #resource) is deprecated. Please use form_for(#resource, :as => :name) instead. (called from _app_views_devise_sessions_new_html_erb___942904761_2291541620_0 at /Users/xonic/Documents/work/ror.ror.at/app/views/devise/sessions/new.html.erb:3)
FDEPRECATION WARNING: Using form_for(:name, #resource) is deprecated. Please use form_for(#resource, :as => :name) instead. (called from _app_views_devise_sessions_new_html_erb___942904761_2291541620_0 at /Users/xonic/Documents/work/ror.ror.at/app/views/devise/sessions/new.html.erb:3)
.DEPRECATION WARNING: Using form_for(:name, #resource) is deprecated. Please use form_for(#resource, :as => :name) instead. (called from _app_views_devise_registrations_new_html_erb__1735759005_2291086140_0 at /Users/xonic/Documents/work/ror.ror.at/app/views/devise/registrations/new.html.erb:3)
So I changed
<%= form_for(resource_name, resource, :url => registration_path(resource_name)) do |f| %>
to
<%= form_for(resource, :url => registration_path(resource_name)) do |f| %>
and got rid of the warnings. So far so good, I continued with my tests and did not try to open the application in the browser myself.
I'm not sure what happened then but all of a sudden, when trying to open the application in the browser, i get the following error message:
NoMethodError in Slides#index
Showing /Users/xonic/Documents/work/ror.ror.at/app/views/layouts/application.html.erb where line #27 raised:
private method `split' called for #<Class:0x10c023278>
Extracted source (around line #27):
24:
25: <div class="gopro">
26:
27: <% if user_signed_in? %>
28: Signed in as <%= link_to current_user.username, user_path(current_user) %>. Not you? <%#, user_slides_path(current_user.username) %>
29: <%= link_to "Sign out", destroy_user_session_path %>
30: <% else %>
So obviously, Devise is in trouble... no idea why. Funny thing is, when calling save_and_open_page while testing the app, a browser window opens with the application displaying correctly and no errors at all.
Guard::RSpec is running, with RSpec 2!
Running all specs
...
Finished in 0.95467 seconds
3 examples, 0 failures
UPDATE:
I've seen this very similar question Devise: NoMethod Error & user_signed_in and have correctly set up the user model, so that's not the problem.
This is quite confusing to me, hopefully someone out there understands what's happening crossingFingers
Thanks,
xon1c
UPDATE
I fixed it, but stackoverflow won't let me answer my own question in the next 6hrs because of lack of reputation sigh. Will post the solution later.
Ok, I fixed it (close to perfect). Here's what i did:
I reverted git to a working status and began from scratch. This time I did not use the line
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
in my Gemfile, instead I only put
gem 'devise'
and then installed the latest devise gem through
gem install devise
rails generate devise:install
The command installed version 1.4.5, not 1.4.7 as I previously had. Then I installed all the other gems, namely capybara, guard-rspec, factory_girl_rails and launchy. Everything works fine now except these two warnings I'm left with:
Running: spec/requests/sign_ups_spec.rb
DEPRECATION WARNING: :name_prefix was deprecated in the new router syntax. Use :as instead. (called from /Users/xonic/Documents/work/ror.ror.at/config/routes.rb:7)
DEPRECATION WARNING: :name_prefix was deprecated in the new router syntax. Use :as instead. (called from /Users/xonic/Documents/work/ror.ror.at/config/routes.rb:7)
.
Finished in 0.16255 seconds
1 example, 0 failures
Well, as long as everything works, I'm ok with the warnings but if anybody knows how to get rid of them, please let me know.
Thanks.
I'm having a hard time getting a simple file upload test working. I'm using Rails 3.0.0 on ruby 1.9.2 with Cucumber and Capybara.
View:
<%= form_tag "/upload/create", :multipart => true do %>
<label for="file">File to Upload:</label>
<%= file_field_tag "file" %>
<%= submit_tag "Upload" %>
<% end %>
Cucumber Step:
When /^I upload the basic file$/ do
visit path_to("upload")
path = File.join(::Rails.root, "somefile")
attach_file("file", path)
click_button("Upload")
end
In my controller, i have commented out everything except for:
def create
file = params[:file]
end
Gemfile snippet:
group :development, :test do
# testing with specs
gem "ZenTest", ">= 4.3.3"
gem "autotest"
gem "rspec-rails", ">= 2.0.0.beta.19", :git => "git://github.com/rspec/rspec-rails.git"
gem "rspec", :git => "git://github.com/rspec/rspec.git"
gem "rspec-core", :git => "git://github.com/rspec/rspec-core.git"
gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
gem "rspec-mocks", :git => "git://github.com/rspec/rspec-mocks.git"
# cucumber stuff
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'spork'
gem 'launchy' # So you can do Then show me the page
gem 'escape_utils' # needed to fix Cucumber - http://crimpycode.brennonbortz.com/?p=42
end
When I try to run the test, I receive:
(::) failed steps (::)
bad content body (EOFError)
<internal:prelude>:10:in `synchronize'
I appreciate any help or insight. Thanks.
This turned out to be an issue with rack-test and it probably won't be a problem for most until more people adopt Rails3 and Ruby 1.9.x.
Upgrading rack-test to the current master branch fixed the problem.
I'm not sure when rack-test will include these changes in the gem.
See also:
groups.google.com/group/cukes/browse_thread/thread/5028306893c2c54a
I don't have an answer but working on the same problem in the same environ - cukes, capybara, rails 3, 1.9.2.... if I figure this out will let you know. Have you thought of posting on the cucumber google group or the Rails google group? If you don't once I get my act together and cant figure out will post to one of these.
Also, it seems that webrat has the method for attach_file() and thus when I generated cucumber without capybara it had a corollary method in web_steps.rb, but after I added capybara and regenerated cucumber it was gone....