Getting an error trying to Route a page (Rails Server) - ruby-on-rails

I'm attempting to try Routing for the first time. I'm following along with a book from Learn-rails.com. Author says to delete what is in config/routes.rb and replace it with: `
LearnRails::Aplication.routes.draw do
root to: redirect('/about.html')
end
After I saved the file, and then refresh localhost:3000 I get this NameError page: http://imgur.com/6pCPAoP
It says:
Tip: add gem "binding_of_caller" to your Gemfile to enable the REPL
and local/instance variable inspection.
Which I did add, and did "bundle install". Then I tried to restart rails server in a new window, and now that won't work. If I remove what the Author said to add to the routes.rb file. Everything is fine. Does anyone have any ideas on what is going on? Thanks!

The screenshot clearly specifies, missing 'p' in LearnRails::Aplication is creating the issue. Just replace and it should work

There are some exception and the better_error is unable to show the error.
Add following line into gem file.
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
Run 'bundle install'
Then check for the exception and post it here, I will try to help with that.

Related

What do I need to do to get the blog to work in rails 4.2?

I have just installed rails 4.2 . I have found this tutorial for making a quick blog: https://www.reinteractive.net/posts/32-ruby-on-rails-3-2-blog-in-15-minutes-step-by-step . However, it uses rails 3.2 . I have done everything that it says up to rake db:migrate and yet, when I run the server, I just get an error page. What has changed since 3.2? what do I now have to do to do the same thing?
error:
'ExecJS::ProgramError in Posts#index'
TypeError: Object doesn't support this property or method
(in C:/Ruby193/lib/ruby/gems/1.9.1/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)
EDIT:
On a side note, I can't even follow the official ruby on rails tutorial because when I run the server, after changing the root to root 'welcome#index' , I just get a page not found error.
Are there any tutorials for rails 4.2?
I had exactly the same ExecJS::ProgramError on Windows. The only solution that really helped was provided by KeithP here: Rails-4, ExecJS::ProgramError in Pages#welcome, i.e.,
Rollback to gem 'coffee-script-source', '1.8.0'.
There's some info here: ExecJS::RuntimeError in Users#index (RoR)
What I found when I looked into this problem was that in CoffeeScript there's a checkin here that I think broke things for Windows (under certain versions of the cscript runtime): https://github.com/jashkenas/coffeescript/blob/28c07d30cbd2add7ee762c7d532b2c9c972e441a/lib/coffee-script/parser.js
On line 563 it's doing an Object create(lexer) which fails with the error ActionView::Template::Error (TypeError: Object doesn't support this property or method.
Rolling back to CoffeeScript 1.8.0 (before this change) works around this problem. As others have stated in this answer and elsewhere, using a different runtime will workaround this problem too.
To roll back to CoffeeScript 1.8.0 add this to your gemfile:
gem 'coffee-script-source', '1.8.0'
And run these commands:
gem update 'coffee-script-source'
bundle update 'coffee-script-source'
Restart your server and it should be working.
This should solve your problem:
Add gem 'therubyracer', '~> 0.12.1' into your gemfile (or uncomment it - should be already there...)
Then run bundle install
Hope this helps.

how to implement "has_messages_generator" on rails3 with devise?

I already created App that I would like to add "has_message_generator" into it.
an auth plugin "Devise" is already installed,so that I followed these dierection below.
Add this line to my Gemfile and did bundle install
gem "has_messages_generators"
Did this command line and it seemed everything's ok!
rails g has_messages:install user
But it shows "uninitialized constant User::HasMessages" error when I access to root page.
so I took "include HasMessages" off from user.rb(in Model directory)
and did "bundle exec rake db:migrate"
It seemed it created table successfully.
Then I tried to access to root page, it still shows error "undefined methodinbox' for #"`
Anyone has idea with the installation of this plugin???
You have to install has_messages, too:
… to use this you must include devise and has_messages in your Gemfile.

NameError in PostsController#pingback

This is my first time trying to get a Gem to work in rails where I haven't just been able to follow the documentation.
I first installed the gem using sudo gem install ping back and then added it to my Gemfile via gem 'pingback'. I then ran bundle install and it shows it installed in the list it outputs.
So then I wrong a little function that looks like this and is in my posts controller:
def send_trackback(posts)
posts.each do |post|
source_uri = "http://example.com/posts/#{post.slug_url}"
target_uri = post.target_url
Pingback::Client.new.ping(source_uri, target_uri)
end
end
whenever I try to load the admin page that sends the trackbacks I get the following:
NameError in PostsController#pingback
uninitialized constant PostsController::Pingback
Do I have to do more than just install the gem via bundler and then plug and play?
Update
adding require 'pingback' to the top of my posts controller results in this:
cannot load such file -- pingback
The error message to me indicates that the VM is trying to find PingBack in PostsController, I am thinking you are missing a require or include statement for PingBack.
It may be a typo, but pingback needs to be one word, not 'ping back' for the line in the gemfile, and for the gem install.
I would try running 'bundle list' to make sure the gem is installed.
I restarted the rails server and I believe this has resolved this issue.

Getting 'undefined method' error or 'no such file to load error' trying to use validates_timeliness gem

I'm trying to use the validates_timeliness gem and followed the install instructions in the documentation: https://github.com/adzap/validates_timeliness
gem 'validates_timeliness', '3.0.2'
bundle install
rails generate validates_timeliness:install
I was then able to successfully add rspec tests and get them to pass using the validates_datetime feature from the gem
However, when I go to my new view in a browser, I get the error:
undefined method 'validates_datetime' for #
I also tried adding require 'validates_timeliness' at the top of the model file and then later at the top of the controller file. In those cases I get the error: 'no such file to load -- validates_timeliness
Any help would be much appreciated, have been trying to do extensive googling.
As noted in the instructions, it must be installed as both a plugin and a gem. When installed as a gem alone, seems to work fine with RSpec, but not in the browser.
How I fixed:
So anyone else that runs into this problem may also try running this code from master to install as plugin:
rails plugin install git://github.com/adzap/validates_timeliness.git
adzap/validates_timeliness#installation

Mimetype-fu isn't working

I feel like this should be an easy answer but I'm totally stumped.
I've added mimetype_fu to my gemfile and it installed it when I ran bundle install. When I try to use File.mime_type? in my application I get an error:
NoMethodError: undefined method `mime_type?' for File:Class
In the rails console when I run
gem 'mimetype-fu'
it returns true
I'm on windows, if that matters
Any ideas?
If you are using Bundler, you can also just add require to the gem line like this.
gem 'mimetype-fu', :require => 'mimetype_fu'
You may need to manually require it inside your rails app. You can do this by adding an file to config/initializers/ if you want it to be available globally.
EDIT | Also, you did restart the rails server, right? ;)

Resources