I'm using a words_import class/controller to allow me to validate my words as I import them from a csv file or excel spreadsheet. Unfortunately I'm receiving an error:
undefined method 'fetch_value' for nil:NilClass
When I attempt to load the words_import#new page. Please help if you can!
importer/app/controllers/word_imports_controller.rb
class WordImportsController < ApplicationController
def new
#word_import = WordImport.new
end
def create
#word_import = WordImport.new(params[:word_import])
if #word_import.save
redirect_to root_url, notice: "Imported words successfully."
else
render :new
end
end
end
importer/app/models/word_import.rb
class WordImport < ApplicationRecord
attr_accessor :file
def initialize(attributes = {})
attributes.each { |name, value| send("#{name}=", value) }
end
def persisted?
false
end
def save
if imported_words.map(&:valid?).all?
imported_words.each(&:save!)
true
else
imported_words.each_with_index do |word, index|
word.errors.full_messages.each do |message|
errors.add :base, "Row #{index+2}: #{message}"
end
end
false
end
end
def imported_words
#imported_words ||= load_imported_words
end
def load_imported_words
spreadsheet = Roo::Spreadsheet.open(file.path)
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
word = Word.find_by(abbreviation: row["abbreviation"]) || Word.new
word.attributes = row.to_hash
word
end
end
end
importer/app/views/product_imports/new.html.erb
<div class="container-fluid">
<div class="jumbotron">
<h1>Import Words</h1>
<p>A CSV or Excel file can be used to import records. The first row should be the column name. The following columns are allowed.</p>
<ul>
<% Word.columns.each do |column| %>
<% if column.name.in? ["id", "name", "released_on", "price"] %>
<li>
<strong><%= column.name %></strong>
<%= column.type.to_s.titleize %> type
</li>
<% end %>
<% end %>
</ul>
<%= form_for #word_import do |f| %>
<% if #word_import.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#word_import.errors.count, "error") %> prohibited this import from completing:</h2>
<ul>
<% #word_import.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.file_field :file %>
</div>
<div class="buttons"><%= f.submit "Import" %></div>
<% end %>
</div>
</div>
importer/config/routes.rb
Rails.application.routes.draw do
root 'words#home'
resources :words, except: [:show] do
collection do
post :import
end
end
get 'results' => 'words#results'
resources :session, only: [:create, :new, :destroy]
resources :word_imports, only: [:create, :new]
end
importer/app/controllers/words_controller
class WordsController < ApplicationController
include ApplicationHelper
before_action :authorize, except: [:index, :home, :results]
def index
#words = Word.order(:abbreviation)
respond_to do |format|
format.html
format.csv { send_data #words.to_csv }
format.xls
end
render :index
end
def create
#word = Word.new(abbreviation: params[:word][:abbreviation], full_word: params[:word][:full_word], definition: params[:word][:definition])
if #word.save
redirect_to results_path
else
#errors = #word.errors.full_messages
render :new
end
end
def new
#word = Word.new(params[:word])
render :new
end
def edit
#word = Word.find(params[:id])
render :edit
end
def update
#word = Word.find(params[:id])
#word.update(abbreviation: params[:word][:abbreviation], full_word: params[:word][:full_word], definition: params[:word][:definition])
if #word.save
redirect_to root_path
else
#errors = #word.errors.full_messages
render :edit
end
end
def destroy
#word = Word.find(params[:id])
#word.destroy
redirect_to root_path
end
def home
render :home
end
def results
#words = Word.search(params[:term])
render :results
end
def import
Word.import(params[:file])
redirect_to root_url, notice: 'Words successfully added.'
end
private
def word_params
params.require(:word).permit(:abbreviation, :full_word, :definition, :term)
end
end
importer/app/models/word
require 'csv'
class Word < ApplicationRecord
include ApplicationHelper
validates :abbreviation, presence: true, length: {maximum: 5}
validates :full_word, presence: true, uniqueness: true
validates :definition, presence: true
def self.search(term)
if term
where('abbreviation iLIKE ?', "%#{term}%").order('full_word DESC')
else
all
end
end
def self.to_csv(options = {})
desired_columns = ["abbreviation", "full_word", "definition"]
CSV.generate(options) do |csv|
csv << desired_columns
all.each do |word|
csv << word.attributes.values_at(*desired_columns)
end
end
end
def self.import(file)
spreadsheet = Roo::Spreadsheet.open(file.path)
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
word = find_by(id: row["id"]) || new
word.attributes = row.to_hash
word.save!
end
end
end
GitHub Repo:
https://github.com/bburnett86/cpf_dictionary
Related
I'm using a words_import class/controller to allow me to validate my words as I import them from a csv file or excel spreadsheet. Unfortunately I'm receiving an error:
undefined method 'fetch_value' for nil:NilClass
When I attempt to load the words_import#new page. Please help if you can!
importer/app/controllers/word_imports_controller.rb
class WordImportsController < ApplicationController
def new
#word_import = WordImport.new
end
def create
#word_import = WordImport.new(params[:word_import])
if #word_import.save
redirect_to root_url, notice: "Imported words successfully."
else
render :new
end
end
end
importer/app/models/word_import.rb
class WordImport < ApplicationRecord
attr_accessor :file
def initialize(attributes = {})
attributes.each { |name, value| send("#{name}=", value) }
end
def persisted?
false
end
def save
if imported_words.map(&:valid?).all?
imported_words.each(&:save!)
true
else
imported_words.each_with_index do |word, index|
word.errors.full_messages.each do |message|
errors.add :base, "Row #{index+2}: #{message}"
end
end
false
end
end
def imported_words
#imported_words ||= load_imported_words
end
def load_imported_words
spreadsheet = Roo::Spreadsheet.open(file.path)
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
word = Word.find_by(abbreviation: row["abbreviation"]) || Word.new
word.attributes = row.to_hash
word
end
end
end
importer/app/views/product_imports/new.html.erb
<div class="container-fluid">
<div class="jumbotron">
<h1>Import Words</h1>
<p>A CSV or Excel file can be used to import records. The first row should be the column name. The following columns are allowed.</p>
<ul>
<% Word.columns.each do |column| %>
<% if column.name.in? ["id", "name", "released_on", "price"] %>
<li>
<strong><%= column.name %></strong>
<%= column.type.to_s.titleize %> type
</li>
<% end %>
<% end %>
</ul>
<%= form_for #word_import do |f| %>
<% if #word_import.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#word_import.errors.count, "error") %> prohibited this import from completing:</h2>
<ul>
<% #word_import.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.file_field :file %>
</div>
<div class="buttons"><%= f.submit "Import" %></div>
<% end %>
</div>
</div>
importer/config/routes.rb
Rails.application.routes.draw do
root 'words#home'
resources :words, except: [:show] do
collection do
post :import
end
end
get 'results' => 'words#results'
resources :session, only: [:create, :new, :destroy]
resources :word_imports, only: [:create, :new]
end
importer/app/controllers/words_controller
class WordsController < ApplicationController
include ApplicationHelper
before_action :authorize, except: [:index, :home, :results]
def index
#words = Word.order(:abbreviation)
respond_to do |format|
format.html
format.csv { send_data #words.to_csv }
format.xls
end
render :index
end
def create
#word = Word.new(abbreviation: params[:word][:abbreviation], full_word: params[:word][:full_word], definition: params[:word][:definition])
if #word.save
redirect_to results_path
else
#errors = #word.errors.full_messages
render :new
end
end
def new
#word = Word.new(params[:word])
render :new
end
def edit
#word = Word.find(params[:id])
render :edit
end
def update
#word = Word.find(params[:id])
#word.update(abbreviation: params[:word][:abbreviation], full_word: params[:word][:full_word], definition: params[:word][:definition])
if #word.save
redirect_to root_path
else
#errors = #word.errors.full_messages
render :edit
end
end
def destroy
#word = Word.find(params[:id])
#word.destroy
redirect_to root_path
end
def home
render :home
end
def results
#words = Word.search(params[:term])
render :results
end
def import
Word.import(params[:file])
redirect_to root_url, notice: 'Words successfully added.'
end
private
def word_params
params.require(:word).permit(:abbreviation, :full_word, :definition, :term)
end
end
importer/app/models/word
require 'csv'
class Word < ApplicationRecord
include ApplicationHelper
validates :abbreviation, presence: true, length: {maximum: 5}
validates :full_word, presence: true, uniqueness: true
validates :definition, presence: true
def self.search(term)
if term
where('abbreviation iLIKE ?', "%#{term}%").order('full_word DESC')
else
all
end
end
def self.to_csv(options = {})
desired_columns = ["abbreviation", "full_word", "definition"]
CSV.generate(options) do |csv|
csv << desired_columns
all.each do |word|
csv << word.attributes.values_at(*desired_columns)
end
end
end
def self.import(file)
spreadsheet = Roo::Spreadsheet.open(file.path)
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
word = find_by(id: row["id"]) || new
word.attributes = row.to_hash
word.save!
end
end
end
require 'roo' in the file containing your class
When I want to go to "localhost:3000/blog" the web page gives this error...
Showing C:/Sites/ifurniture/app/views/refinery/blog/posts/index.html.erb where line #3 raised:
undefined method `to_sym' for {:title=>"Body", :slug=>"body"}:Hash
Rails.root: C:/Sites/ifurniture
this is the blog controller..
module Refinery
module Blog
class PostsController < BlogController
before_filter :find_all_blog_posts, :except => [:archive]
before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
before_filter :find_tags
respond_to :html, :js, :rss
def index
if request.format.rss?
#posts = if params["max_results"].present?
# limit rss feed for services (like feedburner) who have max size
Post.recent(params["max_results"])
else
Post.newest_first.live.includes(:comments, :categories)
end
end
respond_with (#posts) do |format|
format.html
format.rss { render :layout => false }
end
end
def show
#comment = Comment.new
#canonical = refinery.url_for(:locale => Refinery::I18n.current_frontend_locale) if canonical?
#post.increment!(:access_count, 1)
respond_with (#post) do |format|
format.html { present(#post) }
format.js { render :partial => 'post', :layout => false }
end
end
def comment
#comment = #post.comments.create(comment_params)
if #comment.valid?
if Comment::Moderation.enabled? or #comment.ham?
begin
CommentMailer.notification(#comment, request).deliver_now
rescue
logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
end
end
if Comment::Moderation.enabled?
flash[:notice] = t('thank_you_moderated', :scope => 'refinery.blog.posts.comments')
redirect_to refinery.blog_post_url(params[:id])
else
flash[:notice] = t('thank_you', :scope => 'refinery.blog.posts.comments')
redirect_to refinery.blog_post_url(params[:id],
:anchor => "comment-#{#comment.to_param}")
end
else
render :show
end
end
def archive
if params[:month].present?
date = "#{params[:month]}/#{params[:year]}"
archive_date = Time.parse(date)
#date_title = ::I18n.l(archive_date, :format => '%B %Y')
#posts = Post.live.by_month(archive_date).page(params[:page])
else
date = "01/#{params[:year]}"
archive_date = Time.parse(date)
#date_title = ::I18n.l(archive_date, :format => '%Y')
#posts = Post.live.by_year(archive_date).page(params[:page])
end
respond_with (#posts)
end
def tagged
#tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
#tag_name = #tag.name
#posts = Post.live.tagged_with(#tag_name).page(params[:page])
end
private
def comment_params
params.require(:comment).permit(:name, :email, :message)
end
protected
def canonical?
Refinery::I18n.default_frontend_locale != Refinery::I18n.current_frontend_locale
end
end
end
end
the post controller...
module Refinery
module Blog
class PostsController < BlogController
before_filter :find_all_blog_posts, :except => [:archive]
before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
before_filter :find_tags
respond_to :html, :js, :rss
def index
if request.format.rss?
#posts = if params["max_results"].present?
# limit rss feed for services (like feedburner) who have max size
Post.recent(params["max_results"])
else
Post.newest_first.live.includes(:comments, :categories)
end
end
respond_with (#posts) do |format|
format.html
format.rss { render :layout => false }
end
end
def show
#comment = Comment.new
#canonical = refinery.url_for(:locale => Refinery::I18n.current_frontend_locale) if canonical?
#post.increment!(:access_count, 1)
respond_with (#post) do |format|
format.html { present(#post) }
format.js { render :partial => 'post', :layout => false }
end
end
def comment
#comment = #post.comments.create(comment_params)
if #comment.valid?
if Comment::Moderation.enabled? or #comment.ham?
begin
CommentMailer.notification(#comment, request).deliver_now
rescue
logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
end
end
if Comment::Moderation.enabled?
flash[:notice] = t('thank_you_moderated', :scope => 'refinery.blog.posts.comments')
redirect_to refinery.blog_post_url(params[:id])
else
flash[:notice] = t('thank_you', :scope => 'refinery.blog.posts.comments')
redirect_to refinery.blog_post_url(params[:id],
:anchor => "comment-#{#comment.to_param}")
end
else
render :show
end
end
def archive
if params[:month].present?
date = "#{params[:month]}/#{params[:year]}"
archive_date = Time.parse(date)
#date_title = ::I18n.l(archive_date, :format => '%B %Y')
#posts = Post.live.by_month(archive_date).page(params[:page])
else
date = "01/#{params[:year]}"
archive_date = Time.parse(date)
#date_title = ::I18n.l(archive_date, :format => '%Y')
#posts = Post.live.by_year(archive_date).page(params[:page])
end
respond_with (#posts)
end
def tagged
#tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
#tag_name = #tag.name
#posts = Post.live.tagged_with(#tag_name).page(params[:page])
end
private
def comment_params
params.require(:comment).permit(:name, :email, :message)
end
protected
def canonical?
Refinery::I18n.default_frontend_locale != Refinery::I18n.current_frontend_locale
end
end
end
end
and this is the index.html.erb of Blog.
<section class="container">
<% content_for :body do %>
<%= raw #page.content_for(Refinery::Pages.default_parts.first.to_sym) if Refinery::Pages.default_parts.any? %>
<% if #posts.any? %>
<section id="blog_posts" class="news">
<%= render :partial => "/refinery/blog/shared/post", :collection => #posts %>
<%= will_paginate #posts %>
</section>
<% else %>
<p><%= t('.no_blog_articles_yet') %></p>
<% end %>
<% end %>
<% content_for :side_body_prepend do -%>
<%= raw #page.content_for(Refinery::Pages.default_parts.second.to_sym) %>
<% end if Refinery::Pages.default_parts.many? -%>
<%= render "/refinery/content_page" %>
<% content_for :stylesheets, stylesheet_link_tag('refinery/blog/frontend') %>
</section>
I'll be watching for your help, thanks.
You can use to_sym method on hash or string so in your code you can do something like this:
index.html
instead this:
<%= raw #page.content_for(Refinery::Pages.default_parts.first.to_sym) if Refinery::Pages.default_parts.any? %>
put this:
<%= raw #page.content_for(Refinery::Pages.default_parts.first[:title].to_sym) if Refinery::Pages.default_parts.any? %>
instead [:title]you can also use [:slug]
I am getting an error message that says undefined method 'name' in my show.html.erb page. Where it says #book.category.name it keeps saying undefined method name.
show.html.erb
<h1><%= #book.title %></h1>
<h3><%= #book.author %></h3>
<h4>Category: <%= #book.category.name %></h4>
<p><%= #book.description %></p>
<%= link_to "Back", root_path %>
<% if user_signed_in? %>
<% if #book.user_id == current_user.id %>
<%= link_to "edit", edit_book_path(#book) %>
<%= link_to "Delete", book_path(#book), method: :delete, data: {confirm: "Are you sure you want to delete book?"} %>
<% end %>
<% end %>
Books_Controller.rb
class BooksController < ApplicationController
before_action :find_book, only: [:show, :edit, :destroy, :update]
def index
if params[:category].blank?
#books = Book.all.order("created_at DESC")
else
#category_id = Category.find_by(name: params[:category]).id
#books = Book.where(:category_id => #category_id).order("created_at DESC")
end
end
def show
end
def new
#book = current_user.books.build
#categories = Category.all.map{ |c| [c.name, c.id]}
end
def create
#book = current_user.books.build(book_params)
#book.category_id = params[:category_id]
if #book.save
redirect_to root_path
else
render 'new'
end
end
def edit
#categories = Category.all.map{ |c| [c.name, c.id]}
end
def update
#book.category_id = params[:category_id]
if #book.update(book_params)
redirect_to book_path(#book)
else
render ' new'
end
end
def destroy
#book.destroy
redirect_to root_path
end
private
def book_params
params.require(:book).permit(:title, :description, :author, :category_id, :book_img)
end
def find_book
#book = Book.find(params[:id])
end
end
Book.rb
class Book < ActiveRecord::Base
belongs_to :user
belongs_to :category
has_attached_file :book_img, :styles => { :book_index => "250x350>", :book_show => "325x475>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :book_img, :content_type => /\Aimage\/.*\Z/
end
Category.rb
class Category < ActiveRecord::Base
has_many :books
end
Just make sure that specific book has category or just cover it into if statement like below:
<% if #book.category %>
<h4>Category: <%= #book.category.name %></h4>
<% end %>
In case you have to leave category empty is use #try:
<h4>Category: <%= #book.category.try(:name) %></h4>
You need to make sure that the instance #book has a category object.
<h4>Category: <%= #book.category ? #book.category.name : "This book has no category" %></h4>
I wanna fetch feature index page without going through grounddetail id. When i try to create a link in homepage i always get this error:
No route matches {:action=>"index", :controller=>"features", :grounddetail_id=>nil} missing required keys: [:grounddetail_id]
<%= link_to "Account Setting", edit_admin_registration_path %> |
<%= link_to "Log Out", destroy_admin_session_path, method: :delete %> |
<%= link_to "Featured Ground", grounddetail_features_path(#grounddetail) %> # Feature Link Where I get error
grounddetail controller looks :
class GrounddetailsController < ApplicationController
before_action :find_ground, only: [:show, :edit, :destroy, :update]
def index
#grounddetails = Grounddetail.all.order('created_at DESC')
#grounddetail = Grounddetail.first # With this code it run but with grounddetail id.
end
def new
#grounddetail = Grounddetail.new
end
def edit
end
def show
end
def create
#grounddetail = Grounddetail.new(ground_params)
if #grounddetail.save
redirect_to #grounddetail
else
render 'new'
end
end
def update
if #grounddetail.update(ground_params)
redirect_to #grounddetail
else
render 'edit'
end
end
def destroy
#grounddetail.destroy
redirect_to root_path
end
private
def find_ground
#grounddetail = Grounddetail.find(params[:id])
end
def ground_params
params.require(:grounddetail).permit(:name, :working_hours, :end_time, :address, :contact_no, :email, :number_of_grounds, :description, :featured_ground)
end
end
feature controller looks like :
class FeaturesController < ApplicationController
before_action :set_ground
def index
#grounddetails = Grounddetail.where(featured_ground: true).order("created_at DESC")
#features = Feature.includes(:grounddetail).where(grounddetail_id: #grounddetail.id)
end
def new
#feature = Feature.new
end
def show
#feature = Feature.find(params[:id])
end
def edit
#feature = Feature.find(params[:id])
end
def create
#feature = Feature.create(feature_params)
#feature.grounddetail_id = #grounddetail.id
if #feature.save
redirect_to grounddetail_features_path(#grounddetail)
else
render 'new'
end
end
def update
#feature = Feature.find(params[:id])
if #feature.update(feature_params)
redirect_to grounddetail_features_path(#grounddetail)
else
render 'edit'
end
end
def destroy
#feature = Feature.find(params[:id])
#feature.destroy
redirect_to grounddetail_features_path(#grounddetail)
end
private
def set_ground
#grounddetail = Grounddetail.find(params[:grounddetail_id])
end
def feature_params
params.require(:feature).permit(:featuring_start_time, :featuring_end_at)
end
end
Models:
grounddetail model:
has_many :features
feature model:
belongs_to :grounddetail
index.html.erb #feature index page
<h2>Featured Ground</h2>
<% #grounddetails.each do |grounddetail| %>
Name: <%= link_to grounddetail.name, grounddetail %><br>
Address: <%= grounddetail.address %><br>
Opening Hours: From<%= grounddetail.working_hours.strftime("%l:%M %P") %> To <%= grounddetail.end_time.strftime("%l:%M %P") %><br>
Featured : <%= check_box "Grounddetail", "Featured Ground", {checked: grounddetail.featured_ground, disabled: true} %><br>
<% if (grounddetail.featured_ground = true) && (grounddetail_id = #grounddetail.id) %>
<% #features.each do |feature| %>
Featuring Start Time : <%= feature.featuring_start_time.strftime('%e %b %Y %l:%M %P') %><br>
<%# feature.start_date_cannot_be_in_the_past %>
Featuring End At : <%= feature.featuring_end_at.strftime('%e %b %Y %l:%M %P') %><br>
<% end %>
<% end %>
<%= link_to "Add Featuring Time", new_grounddetail_feature_path(#grounddetail) %><br><br>
<% end %>
routes.rb
resources :grounddetails do
resources :features
end
Sorry for the mess up..
name
metric
date_value
result_value
None of the above attributes are showing when I load the index page.
I know its because of this line: <% if averaged.user == current_user %>
More specifically it's because of the nested attributes of date_value and result_value (because if I take out those nested attributes the name & metric will show)
What do I need to add to the controller to allow the nested attributes to show on the index page, and in effect all the attributes?
Thanks in advance for your service!
<div id="values" class="panel panel-default">
<div class="panel-heading"><h4><b>AVERAGE</b></h4></div>
<!-- Table -->
<table>
<% #averaged_quantifieds.each do |averaged| %>
<% if averaged.user == current_user %>
<th class="value">
<%= link_to edit_quantified_path(averaged) do %>
<%= averaged.name %>
<% end %>
(<%= averaged.metric %>)
</th>
<tbody class="value">
<td><%= averaged.date_value.strftime("%m-%Y") %></td>
<td><%= averaged.result_value %></td>
</tbody>
<% end %>
<% end %>
</table>
</div>
controller
class QuantifiedsController < ApplicationController
before_action :set_quantified, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def index
#averaged_quantifieds = current_user.quantifieds.averaged
#instance_quantifieds = current_user.quantifieds.instance
#averaged_quantifieds = Result.all.order("date_value")
#instance_quantifieds = Result.all.order("date_value")
end
def show
end
def new
#quantified = current_user.quantifieds.build
#quantified = Quantified.new
end
def edit
end
def create
#quantified = current_user.quantifieds.build(quantified_params)
if #quantified.save
redirect_to quantifieds_url, notice: 'Quantified was successfully created'
else
render action: 'new'
end
end
def update
if #quantified.update(quantified_params)
redirect_to quantifieds_url, notice: 'Goal was successfully updated'
else
render action: 'edit'
end
end
def destroy
#quantified.destroy
redirect_to quantifieds_url
end
private
def set_quantified
#quantified = Quantified.find(params[:id])
end
def correct_user
#quantified = current_user.quantifieds.find_by(id: params[:id])
redirect_to quantifieds_path, notice: "Not authorized to edit this goal" if #quantified.nil?
end
def quantified_params
params.require(:quantified).permit(:categories, :name, :metric, :result, :date, results_attributes: [:id, :result_value, :date_value, :_destroy])
end
end
quantified.rb
class Quantified < ActiveRecord::Base
belongs_to :user
scope :averaged, -> { where(categories: 'averaged') }
scope :instance, -> { where(categories: 'instance') }
has_many :results
accepts_nested_attributes_for :results, :reject_if => :all_blank, :allow_destroy => true
CATEGORIES = ['averaged', 'instance']
end
Please let me know if you need any more code or comments to help bring this question to a resolution.
This will hopefully guide you in the right direction
This is odd to me
def index
#averaged_quantifieds = current_user.quantifieds.averaged
#instance_quantifieds = current_user.quantifieds.instance
#averaged_quantifieds = Result.all.order("date_value")
#instance_quantifieds = Result.all.order("date_value")
end
You define both of these twice and essentially overwrite each other?
If your attributes aren't showing, it doesn't have anything to do with the nesting, it has to do with the logic. So in other words, this logic
if averaged.user == current_user
is not evaluating to true, so check what each object is actually holding. You can do this in a dirty way by just inspecting it in the view
e.g. put <%= averaged.user.inspect %> and <%= current_user.inspect %>
Once you know what objects it's holding, go backwards in your code to how you altered them to this state. I suspect it'll go back to the controller where you have some issues.