Skip to content

Instantly share code, notes, and snippets.

@holgersindbaek
Last active December 11, 2015 21:39
Show Gist options
  • Save holgersindbaek/4664130 to your computer and use it in GitHub Desktop.
Save holgersindbaek/4664130 to your computer and use it in GitHub Desktop.
Something is wrong here. I keep getting the following error: field articles not an array It saves the magazine and the issue and links up the relationship there. It also links up the relationship on the first article and it saves the second article (without linking it up to the relationship). And then it crashes. What am I doing wrong here?
def publish
require 'parse-ruby-client'
Parse.init :application_id => "App_ID", :api_key => "App_Key"
@magazine = Magazine.find(params[:magazine_id])
@issue = Issue.find(params[:id])
# Checking to see whether we have a magazine already. Making a new one if we don't and grabbing the old one if we do.
current_magazine = Parse::Query.new("Magazine").value_in("title", [@magazine.title]).get
magazine = nil
if current_magazine.length == 0
magazine = Parse::Object.new "Magazine"
magazine["title"] = @magazine.title
magazine["description"] = @magazine.description
magazine.save
else
magazine = current_magazine.first
end
# Checking to see if we have an issue with the same title as the current one. Deleting it if we do.
current_issue = Parse::Query.new("Issue").value_in("title", [@issue.title]).get
issue = nil
if current_issue.length == 0
issue = Parse::Object.new "Issue"
issue["title"] = @issue.title
issue["description"] = @issue.description
issue.save
magazine.array_add_relation("issues", issue.pointer)
magazine.save
else
current_issue.first["title"] = @issue.title
current_issue.first["description"] = @issue.description
current_issue.first.save
issue = current_issue.first
end
# Creating all the articles
@issue.articles.each do |a|
current_article = Parse::Query.new("Article").value_in("title", [a.title]).get
if current_article.length == 0
article = Parse::Object.new "Article"
article["title"] = a.title
article["main_text"] = a.main_text
article.save
issue.array_add_relation("articles", article.pointer)
issue.save
else
current_article.first["title"] = a.title
current_article.first["main_text"] = a.main_text
current_article.first.save
end
end
end
@holgersindbaek
Copy link
Author

This is the exact error I'm getting:

RuntimeError in IssuesController#publish

field articles not an array

app/controllers/issues_controller.rb:46:in `block in publish'
app/controllers/issues_controller.rb:38:in `publish'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment