Rails upgrade to 3.2 routes/locale fails - devise

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

Related

paperclip with amazon s3 working in development but not working in production (amazon ec2)?

I'm pretty new to rails and seem to be having an issue with the paperclip gem. I installed the gem and it works well in development (localhost:3000) but when I'm running it on the amazon server, for some reason it does not want to attach files, and the app breaks (error 500 page).
i have deployed my code to amazon server, i configured bucket details also, but still it is having problem with production, although it works fine with localhost.
Here is the process i ran... I pushed my file to amazon. This did not seem to help.
Here is the code that I have for paperclip:
user.rb model:
has_attached_file :avatar,
:styles => {
:thumb => "50x50",
:medium => "400x400",
:square => "70x70"
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => "mybucket"
my User form:
<%= form_for(#user, url: "/sessions/#{current_user.id}", :html =>{:method => :put, :class => "form-horizontal", :multipart => true}) do |f| %>
<%= f.file_field :avatar %>
<% end %>
breaks down in production. Any pointers would be greatly appreciated... I just cant seem to figure this out and it's pretty frustrating. Thank you so much for your time and any help! please give a pointer where i am making mistake.
Had same issue with image_magic that was breaking our paperclip functionality in production, but not in development (weird, I know). Yet even after removing imagemagick from our gemfile and Gemfile.lock locally (running bundle install and all that stuff) and then deploying back to production on heroku, the error persisted in production! (weird, I know).
What ended up doing the trick was running:
$ heroku repo:purge_cache -a myAppName
(Taken from: https://github.com/heroku/heroku-repo#purge_cache)
When you deploy your app, Heroku caches some things like your assets and installed gems in order to speed up deployment. Although this is a great feature, it can have side-effects sometimes, and in this case, it seems that something about the imagemagick gem got "stuck" in production's cache, which is why purging solved the issue for us (since after purging, your app will rebuild itself from scratch on your next deployment)

acts_as_commentable_with_threading uninitialized constant Post::Comment Rails 3.1.3

I have upgraded my application from Rails 2.3.5 to Rails 3.1.3. I had acts_as_commentable_with_threading and awesome_nested_set as plugins. Now I have added in GemFile for Rails 3.1.3 as below
gem 'awesome_nested_set'
gem 'acts_as_commentable_with_threading'
I have code in the model as below
class Post < ActiveRecord::Base
acts_as_commentable
end
The migration for acts_as_commentable_with_threading is already applied in the database.
I have statement in the view as
<%= pluralize(post.root_comments.size, "comment") %> on this post
When I try to load that view I get error at that line as
uninitialized constant Post::Comment
What can be the problem. Please help me.
Thanks in advance!
You might have forgot to run the generator and the migration afterwards:
rails generate acts_as_commentable_with_threading_migration
or
rails generate acts_as_commentable_upgrade_migration
and after:
bin/rake db:migrate
It's first steps of github repo instructions

Omniauth can't find route

I'm trying to implement Omniauth with my Rails 3 app. I followed the tutorial from the Railscast episod 205, but can't get it to work. When I call the '/auth/twitter' (it doesn't work with any provider) Rails complains it can't find the appropriate route (it tries to load my default route).
I added omniauth.rb under config/initializers/, put gem 'omniauth' in my Gemfile, and ran bundle install.
I'm not sure how to debug this problem nor what information to provide to help understand the problem.
After some research I found a solution. I added the following to my routes.rb file:
get 'auth/:provider' => 'authentications#passthru'
and to my authentications controller:
def passthru
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
Not sure why I had to do that, but it's working...
Here were my steps to get it working:
1) Add omniauth to your Gemfile
2) Add omniauth strategy to your Gemfile (omniauth-linkedin for example)
3) Run bundle install
4) Add the omniauth initializer in config/initializers/omniauth.rb
5) Add the match auth/:provider/callback => users#omniauth route to routes.rb (point it to the controller/action where you'll handle the authentication response)
6) Build the action to handle the authentication response in the controller you referenced in step #4
7) Restart your web server
The default /auth/:provider route wasn't recognized for me until I restarted Apache.
You have to add 'omniauth-twitter' to your gemfile, and
:strategy_class => OmniAuth::Strategies::Twitter
to your omniauth.rb, at the end of the twitter provider.
Then it will recognize the /auth/twitter path.

Getting NoMethodError (undefined method `name' for nil:NilClass) when creating a new model in Heroku console

I just did a push to Heroku and tried doing some testing by adding a model through rails_admin. When I did that I got a generic error page. I went into the logs and noticed this message:
NoMethodError (undefined method `name' for nil:NilClass)
I then opened heroku console and tried adding the model manually and received the same message when trying to save.
NoMethodError: undefined method `name' for nil:NilClass
Here is the model:
class Board < ActiveRecord::Base
attr_accessible :name, :description
validates :name, :presence => true
validates :description, :presence => true
validates_uniqueness_of :name, :case_sensitive => false
has_many :subjects
scope :hidden, where(:is_hidden => true)
scope :visible, where(:is_hidden => false)
end
Any ideas what might be happening with this - or where to start looking?
I did the migration and was able to see that it recognized the model and it's attributes when working in the console.
Thanks!
After being bitten by this issue twice, I asked heroku support team for the reason why it happens. And they replied:
"after running rake db:migrate, you have to restart your application so it can pick up the schema changes, since the schema info is cached during boot in production mode."
So always remember to restart heroku app by 'heroku restart' after running a new migration.
I'm not sure if there is a delay or something with Heroku when pushing changes out and running db:migrate but after spending a few hours out and about, I came back, ran rake db:migrate again, which appeared to do nothing and then I tried creating the model again and it worked without any problems.
So all seems well now, but I can't tell I just needed to wait longer before testing with Heroku - or whether running the migration again actually did something.

map.root does not work in ruby on rails

I have deleted public/index.html.
Here is my config/routes.rb
Those all I have in that file
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
map.root :controller => "home"
I've also tried using map.root :controller => "home#index"
when I ran rake to check
$ rake routes
(in /var/www/atlantix)
/:controller/:action/:id
/:controller/:action/:id.:format
root / {:controller=>"home", :action=>"index"}
I also have:
app/views/home/index.html.erb
app/controllers/home_controller.rb
My issue:
I am a complete newbie of ROR.
I am using Apache and Ruby 1.8.
When I navigate to the http://localhost/myapp/,
I do not see the new home page I created.
Am I missnig something critical in my setup and configuration.
Please advise & help
Mmmm you seem to mix Rails 2 syntax. In Rails 3 you should write:
root :to => 'home#index'
Note: you should also delete the index.html from the public folder.
More information concerning routing can be found here.