'Getting error ActionView::Template::Error (undefined method `each' for nil:NilClass)
I tried to pass some string from a Controllers method to view but it is giving error ActionView::Template::Error (undefined method `each' for nil:NilClass):
These are my code's i tried:
ApplicationController.rb
class ApplicationController < ActionController::Base
private
def baconipsum
@baconipsum ||= Faraday.new("https://baconipsum.com/") do |f|
f.response :json
end
end
end
ArticlesController.rb
def show_Data
#@count = params[:count]
@bacon = baconipsum.get("api/", type: 'all-meat',paras: 2).body
end
_show_data.html.erb
<% @bacon.each do |meat| %>
<p><%= meat %></p>
<%end%>
Here I tried to take user input that how many paragraph he wants to generate and i will pass its value to controller show_data, so that Faraday will generate that number of paragraph for it
Here is my form view
_form_data.html.erb
<%= form_for:article do %>
<label for="value">Value</label>
<%= text_field_tag :value %>
<%= submit_tag "Submit" %>
<% end %>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
