ruby on rails - NoMethodError in Researches#index -
i try make application on rails similar official tutorial http://guides.rubyonrails.org/getting_started.html, instead of articles, have used researches. where's fault if i, when try view list of research, receive error. mistake?
undefined method `name' nil:nilclass
researchescontroller
class researchescontroller < applicationcontroller def new end def show @research = research.find(params[:id]) end def index @researches = research.all end def create @research = research.new(research_params) @research.save redirect_to @research end private def research_params params.require(:research).permit(:name, :period_of_execution, :cost) end end
index.html.erb
<h1>listing of our researches</h1> <table> <tr> <th>name:</th> <th>period of execution:</th> <th>cost:</th> </tr> <% @researches.each |research| %> <tr> <td><%= @research.name %></td> <td><%= @research.period_of_execution %></td> <td><%= @research.cost %></td> </tr> <% end %> </table>
you have write:
<td><%= research.name %></td> <td><%= research.period_of_execution %></td> <td><%= research.cost %></td>
because referencing variable declared here:
<% @researches.each |research| %>
Comments
Post a Comment