I am a complete newbie to the world of Ruby & Rails moving from the land of PHP & Symfony. I'm currently attempting to setup the Facebook Connect plugin & Twitter oAuth for authlogic. Authlogic works no problem but both of the others fail when I attempt to call their buttons- can someone tell me where I'm going wrong? I've put the stack trace below- thanks!
NameError in User_sessions#new
Showing app/views/user_sessions/new.html.haml where line #13 raised:
undefined local variable or method `authlogic_facebook_login_button' for #<ActionView::Base:0x1034fe9e0>
Extracted source (around line #13):
= f.text_field :password
%br
= f.submit "Login"
= authlogic_facebook_login_button
RAILS_ROOT: /Users/nick/Sites/matchmefor-2
Application Trace | Framework Trace | Full Trace
/Users/nick/Sites/matchmefor-2/app/views/user_sessions/new.html.haml:13:in `_run_haml_app47views47user_sessions47new46html46haml'
/Library/Ruby/Gems/1.8/gems/haml-2.2.9/lib/haml/helpers/action_view_mods.rb:164:in `call'
/Library/Ruby/Gems/1.8/gems/haml-2.2.9/lib/haml/helpers/action_view_mods.rb:164:in `form_for'
/Library/Ruby/Gems/1.8/gems/haml-2.2.9/lib/haml/helpers.rb:543:in `call'
/Library/Ruby/Gems/1.8/gems/haml-2.2.9/lib/haml/helpers.rb:543:in `haml_bind_proc'
/Library/Ruby/Gems/1.8/gems/haml-2.2.9/lib/haml/helpers/action_view_mods.rb:170:in `form_for'
/Users/nick/Sites/matchmefor-2/app/views/user_sessions/new.html.haml:4:in `_run_haml_app47views47user_sessions47new46html46haml'
/Library/Ruby/Gems/1.8/gems/haml-2.2.9/lib/haml/helpers/action_view_mods.rb:13:in `render'
/Library/Ruby/Gems/1.8/gems/haml-2.2.9/lib/haml/helpers/action_view_mods.rb:13:in `render'
/Library/Ruby/Gems/1.8/gems/haml-2.2.9/lib/sass/plugin/rails.rb:19:in `process
Related
I am currently working on the Ruby on Rails tutorial by Michael Hartl. I am trying to add a page for each user in my database by creating an HTML with embedded ruby page in the views directory. The code for show.html.erb is below:
<%= #user.name %>, <%= #user.email %>
When I add the user to the user_controller.rb file, it looks like this:
class UsersController < ApplicationController
def show
#user = User.find(params[:id])
end
def new
end
end
When I run the rails server and click on open up the users/1 URL, I get a NameError complaining about an uninitialized constant. The error and trace is below:
NameError in UsersController#show
uninitialized constant UsersController::User
Rails.root: /usr/sample_app
Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:3:in `show'
actionpack (3.2.12) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.12) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.12) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.12) lib/active_support/callbacks.rb:414:in
.
.
.
.
Please let me know how to go about this because I cannot pass my spec tests with this error. If anyone has any suggestions or insight I would greatly appreciate them.Thank you.
Controller file name should be users_controller.rb
As you mentioned in comment you don't have any User model defined. To create model run rails g model user name:string email:string. This will create User model with attributes name and email.
Try Rails scaffolding and see what files it creates(in controller, model and views ignore other files for now) and see the contents of those files. To use scaffold for creating User is as below:
rails g scaffold user name:string email:string
rake db:migrate
I am newbie with Shapado. I’m trying to install shapado in my laptop (MAC OS) and when I try to access to http://localhost.lan:3000 I have the following error:
NoMethodError in Questions#index
Showing /Users/sciruela/Documents/shapado/shapado/app/views/shared/_login_drop_down.html.haml where line #10 raised:
undefined method `[]' for nil:NilClass
Extracted source (around line #10):
7: = link_to provider.titleize, '/users/auth/facebook', :class => 'auth-provider Facebook', :id => 'facebook'
8: - else
9: %li
10: = link_to provider.titleize, multiauth_url(provider), :class => "auth-provider #{provider}", :id => dprovider
11:
12: -if current_group.allow_any_openid
13: %li
Trace of template inclusion: app/views/shared/_login_menu.html.haml, app/views/shared/_topbar.html.haml, app/views/layouts/application.html.haml
Rails.root: /Users/sciruela/Documents/shapado/shapado
Application Trace | Framework Trace | Full Trace
app/views/shared/_login_drop_down.html.haml:10:in `block in _app_views_shared__login_drop_down_html_haml__1123238317393261506_2159776840'
app/views/shared/_login_drop_down.html.haml:2:in `each'
app/views/shared/_login_drop_down.html.haml:2:in `_app_views_shared__login_drop_down_html_haml__1123238317393261506_2159776840'
app/views/shared/_login_menu.html.haml:6:in `_app_views_shared__login_menu_html_haml___434956048083202339_2193663100'
app/helpers/application_helper.rb:36:in `multiauth_dropdown'
app/views/shared/_topbar.html.haml:21:in `_app_views_shared__topbar_html_haml___2782218627514502243_2204427320'
app/views/layouts/application.html.haml:10:in `block in _app_views_layouts_application_html_haml___4514694021451724572_2205033860'
app/helpers/layout_helper.rb:74:in `call'
app/helpers/layout_helper.rb:74:in `block in ie_tag'
app/helpers/layout_helper.rb:72:in `ie_tag'
app/helpers/layout_helper.rb:79:in `ie_html'
app/views/layouts/application.html.haml:2:in `_app_views_layouts_application_html_haml___4514694021451724572_2205033860'
app/controllers/application_controller.rb:122:in `block (2 levels) in find_questions'
app/controllers/application_controller.rb:121:in `find_questions'
app/controllers/questions_controller.rb:67:in `index'
lib/sso_strategy.rb:18:in `call!'
app/middlewares/dynamic_domain.rb:17:in `call'
Request
How I could solve it?
Thanks
In Rails, the [] acts as a reader and []= as a setter. It looks like the issue is occurring on line 10 at multiauth_url(provider).
It also appears that provider is nil in this case. I suggest using pry (a gem) and drop in binding.pry to debug further. You might be making the assumption that a provider always exists, so verify that provider is not nil first.
did you follow shapado's Readme? seems like you did not this step
https://github.com/ricodigo/shapado/blob/master/README#L25
I am trying to get basic authentication working using devise and mongomapper.
Following the instructions here:
http://johnwyles.com/2010/03/15/sessions-in-mongodb-using-mongomapper-and-devise/
(except deferring the routes.rb changes until after the generators are run to address errors)
I got it as far as getting the following paths to work:
/users/sign_up ::
/users/sign_in ::
/users/password/new ::
/users/confirmation/new
However, just trying to hit "/" gives me an error
NameError in UserController#sign_in
uninitialized constant UserController
RAILS_ROOT: /Users/bentrevino/Documents/Dev/devisetest
Application Trace | Framework Trace | Full Trace
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:364:in `constantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:363:in `each'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:363:in `constantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/routing/route_set.rb:444:in `recognize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/routing/route_set.rb:437:in `call'
After I submit a sign-up request, I get this error
RuntimeError in Registrations#create
Showing /Library/Ruby/Gems/1.8/gems/devise-1.0.8/app/views/devise_mailer/confirmation_instructions.html.erb where line #5 raised:
Missing host to link to! Please provide :host parameter or set default_url_options[:host]
Extracted source (around line #5):
2:
3: <p>You can confirm your account through the link below:</p>
4:
5: <p><%= link_to 'Confirm my account', confirmation_url(#resource, :confirmation_token => #resource.confirmation_token) %></p>
Does anybody know what might be going on here?
Thanks!
Ben....
At least one issue you are having is that you have not created a controller for your root route that you specified in config/routes.rb file. Run a call to rails generate controller [name] to make a new controller. Then specify that name in your config/routes.rb file for our root route.
I'm trying to get the rails-ckeditor gem to work. I followed the instructions on the README.
But I get this error
undefined method `html_safe?' for #<String:0xb6b6d080>
This is my formtastic form code:
<%= f.input :content, :as => :ckeditor %>
Any ideas? Thanks!
UPDATE
I'm using Rails 2.3.8. And here's the stack trace.
/usr/lib/ruby/gems/1.8/gems/ckeditor-3.4.3/lib/ckeditor/safe_buffer.rb:6:in `<<'
/usr/lib/ruby/gems/1.8/gems/ckeditor-3.4.3/lib/ckeditor/view_helper.rb:52:in `ckeditor_textarea'
/usr/lib/ruby/gems/1.8/gems/ckeditor-3.4.3/lib/ckeditor/formtastic.rb:9:in `send'
/usr/lib/ruby/gems/1.8/gems/ckeditor-3.4.3/lib/ckeditor/formtastic.rb:9:in `ckeditor_input'
/usr/lib/ruby/gems/1.8/gems/formtastic-1.1.0/lib/formtastic.rb:1281:in `send'
/usr/lib/ruby/gems/1.8/gems/formtastic-1.1.0/lib/formtastic.rb:1281:in `inline_input_for'
/usr/lib/ruby/gems/1.8/gems/formtastic-1.1.0/lib/formtastic.rb:109:in `send'
/usr/lib/ruby/gems/1.8/gems/formtastic-1.1.0/lib/formtastic.rb:109:in `input'
/usr/lib/ruby/gems/1.8/gems/formtastic-1.1.0/lib/formtastic.rb:108:in `map'
/usr/lib/ruby/gems/1.8/gems/formtastic-1.1.0/lib/formtastic.rb:108:in `input'
/home/shreyas/repos/citymgmt/app/views/articles/_form.html.erb:4
/home/shreyas/repos/citymgmt/app/views/articles/_form.html.erb:2:in `_run_erb_app47views47articles47_form46html46erb_locals_form_object'
/home/shreyas/repos/citymgmt/app/views/articles/_form.html.erb:1:in `_run_erb_app47views47articles47_form46html46erb_locals_form_object'
/home/shreyas/repos/citymgmt/app/views/articles/new.html.erb:10
/home/shreyas/repos/citymgmt/app/views/articles/new.html.erb:3:in `_run_erb_app47views47articles47new46html46erb'
Are you running an earlier version of Rails than 3.0.0? You'll want to install the rails_xss plugin which provides this functionality. In Rails 3, this comes standard.
I would advise, if at all possible, to upgrade to Rails 3 as soon as you are able.
Do you have a stack trace? Based on the error, I'm assuming that the plugin load order is causing a string to not be instantiated with SafeBuffer support (which also leads me to believe you're using Rails 2).
Can you provide some context?
Strange error in diagnostics.erb file about _set_controller_content_type.
Please help.
NoMethodError in Timelines#public_timeline
Showing /opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/templates/rescues/diagnostics.erb where line # raised:
undefined method `content_type' for nil:NilClass
Extracted source (around line #):
RAILS_ROOT: /Volumes/DATA/Source/Rails/tvider
Application Trace | Framework Trace | Full Trace
/opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/whiny_nil.rb:52:in `method_missing'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/base.rb:331:in `_set_controller_content_type'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/renderable.rb:32:in `block in render'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/base.rb:306:in `with_template'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/renderable.rb:30:in `render'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/template.rb:205:in `render_template'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/base.rb:265:in `render'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:134:in `rescue_action_locally'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:152:in `rescue_action_without_handler'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:74:in `rescue_action'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:162:in `rescue in perform_action_with_rescue'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:160:in `perform_action_with_rescue'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/flash.rb:146:in `perform_action_with_flash'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `process'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/filters.rb:606:in `process_with_filters'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/base.rb:391:in `process'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/base.rb:386:in `call'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:437:in `call'
Request
Parameters:
None
Show session dump
Response
Headers:
{"Cache-Control"=>"no-cache",
"Content-Type"=>""}
I don't know if this is the cause of your error. But when I got this error, it was because I unthinkingly defined a "response" action in my controller. Renamed the action, and all was well.
Code Example:
class PagesController < ApplicationController
def request
end
def response
end
end
What action are you trying to call in the controller ?
check the action_name in the controller !