-2

I tried hard to find this exact match of my error but I am unable to do so. I am new to Ruby and stuck for long after this block. Please help. I have checked my route.rb file my controller method show and my show.html.erb file error remains.
I destroyed and created controller again and again to check but still the error remains.
Is it asking me to define/declare variable user?? have not I did so?? like in controller i did @user and then called databsae.. I think so.
Thanks in advance

The controller:

class PersonsController < ApplicationController

  def show
  @user = Users.find(params[:id])

  end
end

The view:

<%= provide(:title, @user.name %>
<h1> @user.name </h1>
<%=@user.name %>, <%=@user.email %>

The routes:

Rails.application.routes.draw do
  get 'persons/show'

  root 'staticpages#home'

  get 'help' => 'staticpages#help'

  get 'about' => 'staticpages#about'

  resources :persons
  resources :person

end
Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
usman ali
  • 1
  • 7
  • could you please paste the error text, also in the view you used `provide(:title, @user.name` , what is this for? also it's missing a bracket. – Mohammad AbuShady Aug 06 '15 at 09:01

1 Answers1

1

Model names in Rails are singular:

@user = User.find(params[:id])
Marek Lipka
  • 50,622
  • 7
  • 87
  • 91
  • SyntaxError in PersonsController#show now this error occured. these both are coming simultaneously :( @Marek Lipka – usman ali Aug 06 '15 at 08:48
  • @usmanali you must have done something wrong with copy/pasting my snippet. – Marek Lipka Aug 06 '15 at 08:49
  • Sir @Marek Its okay down voting me. But it did not helped me at all. I copy pasted but error says.. ActiveRecord::RecordNotFound in PersonsController#show Where as I have used ruby console and debug to check record the user exists in table. Kindly help me getting out of this – usman ali Aug 06 '15 at 08:53
  • What params do you pass into your controller? – Marek Lipka Aug 06 '15 at 08:56
  • 1
    BTW in my opinion you should spend some time on learning Ruby/Rails basics. – Marek Lipka Aug 06 '15 at 08:59
  • I tried passing 1 and my url is somehow /persons/1 and I also tried /persons/show both gave me errors – usman ali Aug 06 '15 at 08:59
  • `/persons/show` won't work, that's why you should learn some basics at the beginning. `/persons/1` will work only if there is `User` record with id of 1. What does `/persons/1` call return? What does `User.find(1)` return in your console? – Marek Lipka Aug 06 '15 at 09:02
  • User.find('1') User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]] => # this is what my console says about User.find('1') @Marek – usman ali Aug 06 '15 at 09:06
  • And what's the result of `/persons/1` call? – Marek Lipka Aug 06 '15 at 09:06
  • I bet it's syntax error. Instead of `<%= provide(:title, @user.name %>` you should have `<%= provide(:title, @user.name) %>`. – Marek Lipka Aug 06 '15 at 09:08
  • Thank you very much @Marek. yes I am learning. At times I am stuck I seek for help fromk seniors. Thanks and down voting blocks me frrom further asking :( – usman ali Aug 06 '15 at 09:10
  • It's a good thing in my opinion - you should try to solve this kind of problems on your own before asking here. – Marek Lipka Aug 06 '15 at 09:11