0
votes

this is the subjects_controller

class SubjectsController < ApplicationController
 layout false
 def index
 @subjects = Subject.order("position ASC")
 end

 def show

 @subject = Subject.find(params[:id])

 end

 def new
 end

 def edit
 end

 def delet
 end
end

and this is the 'show.html.erb'

<%= link_to("<< Back to List", {:class => 'index'})  :class => 'back-   link)'%>
<div class ="subjects show">
<h2>Show Subject</h2>

<table sammary="Subject detail view">
 <tr>
     <th>Name</th>

     <td><%=  @subject.name  %></td>
 </tr>
 <tr>
    <th>Position</th>
    <td><%= @subject.position %> </th>
 </tr>
  <tr>
    <th>Visible</th>
    <td><%= @subject.visible ? 'true': 'flse' %> </th>
 </tr>
 <tr>
    <th>Created</th>
    <td><%= @subject.created_at %> </th>
 </tr>
 <tr>
    <th>Updated</th>
    <td><%= @subject.updated_at %> </th>
 </tr>
 </table>
</div>

so when i click on something on the browser i don't get anything and when i did this on rails console

Subject.find(params[:id]) 

i get this message
NameError: undefined local variable or method `params' for main:Object from (irb):7

2
because irb/console doesn't know what params is. - uday

2 Answers

0
votes

params is undefined in your current console context. You're trying to recreate controller code in your console. In the controller, params is automatically assigned according to the incoming HTTP request parameters. In the console params is undefined unless you explicitly assign it. Try this in your console:

params = {id: 1}
Subject.find(params[:id]) 

It will not throw an error if Subject is in fact an ActiveRecord model.

What are you really trying to accomplish?

0
votes

If you want to debug your controller, use pry or byebug to get a debug console for the specific context for example:

def edit
  binding.pry
  @subject = Subject.find(params[:id])
end

Go to the subjects/1/edit path, rails server stops at the break point and you can access the debug console.