Model Initialization - Passing parameters - Rails 5How can I “pretty” format my JSON output in Ruby on Rails?How to pass command line arguments to a rake taskA concise explanation of nil v. empty v. blank in Ruby on RailsUnderstanding the Rails Authenticity TokenUndo scaffolding in RailsPassing parameters in rails redirect_toHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?How to redirect to a 404 in Rails?How to drop columns using Rails migration
Theorems that impeded progress
Arrow those variables!
Is "remove commented out code" correct English?
Is there a hemisphere-neutral way of specifying a season?
Is it unprofessional to ask if a job posting on GlassDoor is real?
What's the point of deactivating Num Lock on login screens?
Emailing HOD to enhance faculty application
Did Shadowfax go to Valinor?
How to take photos in burst mode, without vibration?
What is the most common color to indicate the input-field is disabled?
Facing a paradox: Earnshaw's theorem in one dimension
I Accidentally Deleted a Stock Terminal Theme
What killed these X2 caps?
Combinations of multiple lists
Is the Joker left-handed?
What does it mean to describe someone as a butt steak?
Why do I get two different answers for this counting problem?
How to model explosives?
Intersection of two sorted vectors in C++
Will google still index a page if I use a $_SESSION variable?
Why are electrically insulating heatsinks so rare? Is it just cost?
Do I have a twin with permutated remainders?
Forgetting the musical notes while performing in concert
Is it possible to create light that imparts a greater proportion of its energy as momentum rather than heat?
Model Initialization - Passing parameters - Rails 5
How can I “pretty” format my JSON output in Ruby on Rails?How to pass command line arguments to a rake taskA concise explanation of nil v. empty v. blank in Ruby on RailsUnderstanding the Rails Authenticity TokenUndo scaffolding in RailsPassing parameters in rails redirect_toHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?How to redirect to a 404 in Rails?How to drop columns using Rails migration
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am having trouble initializing my model.
I am trying to build a model which takes a url_address string on initialization, utilizes DocRaptor to build a PDF, then uses pdf-reader to read data from that PDF, and finally remove the stored PDF.
When I have a blank model, I can save using Rails 5 forms, as per the introductory Rails 5 guide, here: https://guides.rubyonrails.org/getting_started.html
I built a new project from scratch using a postgresql database, and set about with the Guide. I was able to save models just fine with a blank UrlDataModel definition. However, when I edited my model to contain functionality necessary to retrieve the PDF and read it, I get a
NoMethodError - undefined method '[]' for nil:Class
I do know this error means that my model is empty, so I'm trying to troubleshoot how that happens.
The controller fails on
@url_data_model.save
My repo is here: https://github.com/blueMesaEngineering/Minotaur-hoof
Model follows here:
class UrlDataModel < ApplicationRecord
attr_accessor :url_address, :pdf_version, :producer, :title, :metadata, :page_count
def initialize(attributes = )
@url_address = attributes[:url_address]
@pdf_version = attributes[:pdf_version]
@producer = attributes[:producer]
@title = attributes[:title]
@metadata = attributes[:metadata]
@page_count = attributes[:page_count]
end
def after_initialize
buildModelFromURLViaPDF
end
def buildModelFromURLViaPDF
convertURLToPDF
readPDFData
deletePDF
end
def convertURLToPDF
require 'bundler/setup'
Bundler.require
DocRaptor.configure do |dr|
dr.username = 'YOUR_API_KEY_HERE' # this key works for test documents
# dr.debugging = true
end
$docraptor = DocRaptor::DocApi.new
begin
logPathName = './storage/Logs/standardOutput/output.txt'
errorLogPathName = './storage/Logs/Error/'
pathName = './storage/PDFs/'
# url = "http://docraptor.com/examples/invoice.html"
url = 'http://www.docraptor.com'
@url_address = url
fileNamePDF = 'docraptor-ruby.pdf'
create_response = $docraptor.create_async_doc(
test: true, # test documents are free but watermarked
document_url: url, # or use a url
name: fileNamePDF, # help you find a document later
document_type: 'pdf' # pdf or xls or xlsx
)
loop do
status_response = $docraptor.get_async_doc_status(create_response.status_id)
# puts "doc status: #status_response.status"
case status_response.status
when 'completed'
doc_response = $docraptor.get_async_doc(status_response.download_id)
File.open('./storage/PDFs/docraptor-ruby.pdf', 'wb') do |file|
file.write(doc_response)
end
# puts "Wrote PDF to " + pathName + fileNamePDF
break
when 'failed'
# puts "FAILED"
# puts status_response
break
else
sleep 1
end
end
rescue DocRaptor::ApiError => error
# puts "#error.class: #error.message"
# puts error.code # HTTP response code
# puts error.response_body # HTTP response body
# puts error.backtrace[0..3].join("n")
end
end
def readPDFData
require 'rubygems'
require 'pdf/reader'
fileName = './storage/PDFs/docraptor-ruby.pdf'
PDF::Reader.open(fileName) do |reader|
@pdf_version = reader.pdf_version
# @producer = reader.producer
# @title = reader.title
@metadata = reader.metadata
@page_count = reader.page_count
end
end
def deletePDF
require 'fileutils'
FileUtils.rm_rf('./storage/PDFs/docraptor-ruby.pdf')
end
end
Penny for your thoughts? I'm on here for the rest of the evening, so I will be able to respond directly. Thank you for taking a look!
Cheers.
Controller: https://pastebin.com/QVaHCMep
Stack Trace: https://pastebin.com/uQbXgiaH
ruby-on-rails ruby model
|
show 1 more comment
I am having trouble initializing my model.
I am trying to build a model which takes a url_address string on initialization, utilizes DocRaptor to build a PDF, then uses pdf-reader to read data from that PDF, and finally remove the stored PDF.
When I have a blank model, I can save using Rails 5 forms, as per the introductory Rails 5 guide, here: https://guides.rubyonrails.org/getting_started.html
I built a new project from scratch using a postgresql database, and set about with the Guide. I was able to save models just fine with a blank UrlDataModel definition. However, when I edited my model to contain functionality necessary to retrieve the PDF and read it, I get a
NoMethodError - undefined method '[]' for nil:Class
I do know this error means that my model is empty, so I'm trying to troubleshoot how that happens.
The controller fails on
@url_data_model.save
My repo is here: https://github.com/blueMesaEngineering/Minotaur-hoof
Model follows here:
class UrlDataModel < ApplicationRecord
attr_accessor :url_address, :pdf_version, :producer, :title, :metadata, :page_count
def initialize(attributes = )
@url_address = attributes[:url_address]
@pdf_version = attributes[:pdf_version]
@producer = attributes[:producer]
@title = attributes[:title]
@metadata = attributes[:metadata]
@page_count = attributes[:page_count]
end
def after_initialize
buildModelFromURLViaPDF
end
def buildModelFromURLViaPDF
convertURLToPDF
readPDFData
deletePDF
end
def convertURLToPDF
require 'bundler/setup'
Bundler.require
DocRaptor.configure do |dr|
dr.username = 'YOUR_API_KEY_HERE' # this key works for test documents
# dr.debugging = true
end
$docraptor = DocRaptor::DocApi.new
begin
logPathName = './storage/Logs/standardOutput/output.txt'
errorLogPathName = './storage/Logs/Error/'
pathName = './storage/PDFs/'
# url = "http://docraptor.com/examples/invoice.html"
url = 'http://www.docraptor.com'
@url_address = url
fileNamePDF = 'docraptor-ruby.pdf'
create_response = $docraptor.create_async_doc(
test: true, # test documents are free but watermarked
document_url: url, # or use a url
name: fileNamePDF, # help you find a document later
document_type: 'pdf' # pdf or xls or xlsx
)
loop do
status_response = $docraptor.get_async_doc_status(create_response.status_id)
# puts "doc status: #status_response.status"
case status_response.status
when 'completed'
doc_response = $docraptor.get_async_doc(status_response.download_id)
File.open('./storage/PDFs/docraptor-ruby.pdf', 'wb') do |file|
file.write(doc_response)
end
# puts "Wrote PDF to " + pathName + fileNamePDF
break
when 'failed'
# puts "FAILED"
# puts status_response
break
else
sleep 1
end
end
rescue DocRaptor::ApiError => error
# puts "#error.class: #error.message"
# puts error.code # HTTP response code
# puts error.response_body # HTTP response body
# puts error.backtrace[0..3].join("n")
end
end
def readPDFData
require 'rubygems'
require 'pdf/reader'
fileName = './storage/PDFs/docraptor-ruby.pdf'
PDF::Reader.open(fileName) do |reader|
@pdf_version = reader.pdf_version
# @producer = reader.producer
# @title = reader.title
@metadata = reader.metadata
@page_count = reader.page_count
end
end
def deletePDF
require 'fileutils'
FileUtils.rm_rf('./storage/PDFs/docraptor-ruby.pdf')
end
end
Penny for your thoughts? I'm on here for the rest of the evening, so I will be able to respond directly. Thank you for taking a look!
Cheers.
Controller: https://pastebin.com/QVaHCMep
Stack Trace: https://pastebin.com/uQbXgiaH
ruby-on-rails ruby model
A couple (or four) things. First, you should probably put the whole stack trace in your question (it's often easier to get a sense of the error and where it might be coming from). Second, IMO you are significantly overloading the responsibility of that model. Third, it seems strange to have thoserequire
statements sprinkled throughout (and configure statements, too). Fourth, and finally, it looks like a global variable in there ($docraptor
) which might not be a big deal but I personally never use.
– jvillian
Mar 8 at 0:29
Where is the code where you are actually initializing the model and saving it? Post it here please. And you should probably remove the comments in your code here, doesn't really help us to solve your problem.
– Antarr Byrd
Mar 8 at 0:51
Hello - Thanks for the response. I am self-taught with respect to Ruby and Rails, so I am always learning. Some of the apparent globals ($docraptor) were in some of the documentation, but I will take it under advisement. Some things seemed to break when I left requires in the higher level of the class, but I will double check. Should some of this be in the controller? I was building this under the guidelines of a "thin controller" model. I'm not sure if that's best though. Comments have been removed accordingly. Thank you for your help!
– ND Guthrie
Mar 8 at 1:57
Heroku app: murmuring-chamber-54696.herokuapp.com
– ND Guthrie
Mar 8 at 2:00
I would advise opening rails console and trying to save a record with the same attributes you'd get from the controller. If there's an error look at the stack trace to determine what line it originated from. I'm afraid without this info this question is impossible to answer. I'm assuming that since you can call@url_data_model.save
you have already initialized the record without error. None of the other model code actually gets run with the code you've shown
– max pleaner
Mar 8 at 9:53
|
show 1 more comment
I am having trouble initializing my model.
I am trying to build a model which takes a url_address string on initialization, utilizes DocRaptor to build a PDF, then uses pdf-reader to read data from that PDF, and finally remove the stored PDF.
When I have a blank model, I can save using Rails 5 forms, as per the introductory Rails 5 guide, here: https://guides.rubyonrails.org/getting_started.html
I built a new project from scratch using a postgresql database, and set about with the Guide. I was able to save models just fine with a blank UrlDataModel definition. However, when I edited my model to contain functionality necessary to retrieve the PDF and read it, I get a
NoMethodError - undefined method '[]' for nil:Class
I do know this error means that my model is empty, so I'm trying to troubleshoot how that happens.
The controller fails on
@url_data_model.save
My repo is here: https://github.com/blueMesaEngineering/Minotaur-hoof
Model follows here:
class UrlDataModel < ApplicationRecord
attr_accessor :url_address, :pdf_version, :producer, :title, :metadata, :page_count
def initialize(attributes = )
@url_address = attributes[:url_address]
@pdf_version = attributes[:pdf_version]
@producer = attributes[:producer]
@title = attributes[:title]
@metadata = attributes[:metadata]
@page_count = attributes[:page_count]
end
def after_initialize
buildModelFromURLViaPDF
end
def buildModelFromURLViaPDF
convertURLToPDF
readPDFData
deletePDF
end
def convertURLToPDF
require 'bundler/setup'
Bundler.require
DocRaptor.configure do |dr|
dr.username = 'YOUR_API_KEY_HERE' # this key works for test documents
# dr.debugging = true
end
$docraptor = DocRaptor::DocApi.new
begin
logPathName = './storage/Logs/standardOutput/output.txt'
errorLogPathName = './storage/Logs/Error/'
pathName = './storage/PDFs/'
# url = "http://docraptor.com/examples/invoice.html"
url = 'http://www.docraptor.com'
@url_address = url
fileNamePDF = 'docraptor-ruby.pdf'
create_response = $docraptor.create_async_doc(
test: true, # test documents are free but watermarked
document_url: url, # or use a url
name: fileNamePDF, # help you find a document later
document_type: 'pdf' # pdf or xls or xlsx
)
loop do
status_response = $docraptor.get_async_doc_status(create_response.status_id)
# puts "doc status: #status_response.status"
case status_response.status
when 'completed'
doc_response = $docraptor.get_async_doc(status_response.download_id)
File.open('./storage/PDFs/docraptor-ruby.pdf', 'wb') do |file|
file.write(doc_response)
end
# puts "Wrote PDF to " + pathName + fileNamePDF
break
when 'failed'
# puts "FAILED"
# puts status_response
break
else
sleep 1
end
end
rescue DocRaptor::ApiError => error
# puts "#error.class: #error.message"
# puts error.code # HTTP response code
# puts error.response_body # HTTP response body
# puts error.backtrace[0..3].join("n")
end
end
def readPDFData
require 'rubygems'
require 'pdf/reader'
fileName = './storage/PDFs/docraptor-ruby.pdf'
PDF::Reader.open(fileName) do |reader|
@pdf_version = reader.pdf_version
# @producer = reader.producer
# @title = reader.title
@metadata = reader.metadata
@page_count = reader.page_count
end
end
def deletePDF
require 'fileutils'
FileUtils.rm_rf('./storage/PDFs/docraptor-ruby.pdf')
end
end
Penny for your thoughts? I'm on here for the rest of the evening, so I will be able to respond directly. Thank you for taking a look!
Cheers.
Controller: https://pastebin.com/QVaHCMep
Stack Trace: https://pastebin.com/uQbXgiaH
ruby-on-rails ruby model
I am having trouble initializing my model.
I am trying to build a model which takes a url_address string on initialization, utilizes DocRaptor to build a PDF, then uses pdf-reader to read data from that PDF, and finally remove the stored PDF.
When I have a blank model, I can save using Rails 5 forms, as per the introductory Rails 5 guide, here: https://guides.rubyonrails.org/getting_started.html
I built a new project from scratch using a postgresql database, and set about with the Guide. I was able to save models just fine with a blank UrlDataModel definition. However, when I edited my model to contain functionality necessary to retrieve the PDF and read it, I get a
NoMethodError - undefined method '[]' for nil:Class
I do know this error means that my model is empty, so I'm trying to troubleshoot how that happens.
The controller fails on
@url_data_model.save
My repo is here: https://github.com/blueMesaEngineering/Minotaur-hoof
Model follows here:
class UrlDataModel < ApplicationRecord
attr_accessor :url_address, :pdf_version, :producer, :title, :metadata, :page_count
def initialize(attributes = )
@url_address = attributes[:url_address]
@pdf_version = attributes[:pdf_version]
@producer = attributes[:producer]
@title = attributes[:title]
@metadata = attributes[:metadata]
@page_count = attributes[:page_count]
end
def after_initialize
buildModelFromURLViaPDF
end
def buildModelFromURLViaPDF
convertURLToPDF
readPDFData
deletePDF
end
def convertURLToPDF
require 'bundler/setup'
Bundler.require
DocRaptor.configure do |dr|
dr.username = 'YOUR_API_KEY_HERE' # this key works for test documents
# dr.debugging = true
end
$docraptor = DocRaptor::DocApi.new
begin
logPathName = './storage/Logs/standardOutput/output.txt'
errorLogPathName = './storage/Logs/Error/'
pathName = './storage/PDFs/'
# url = "http://docraptor.com/examples/invoice.html"
url = 'http://www.docraptor.com'
@url_address = url
fileNamePDF = 'docraptor-ruby.pdf'
create_response = $docraptor.create_async_doc(
test: true, # test documents are free but watermarked
document_url: url, # or use a url
name: fileNamePDF, # help you find a document later
document_type: 'pdf' # pdf or xls or xlsx
)
loop do
status_response = $docraptor.get_async_doc_status(create_response.status_id)
# puts "doc status: #status_response.status"
case status_response.status
when 'completed'
doc_response = $docraptor.get_async_doc(status_response.download_id)
File.open('./storage/PDFs/docraptor-ruby.pdf', 'wb') do |file|
file.write(doc_response)
end
# puts "Wrote PDF to " + pathName + fileNamePDF
break
when 'failed'
# puts "FAILED"
# puts status_response
break
else
sleep 1
end
end
rescue DocRaptor::ApiError => error
# puts "#error.class: #error.message"
# puts error.code # HTTP response code
# puts error.response_body # HTTP response body
# puts error.backtrace[0..3].join("n")
end
end
def readPDFData
require 'rubygems'
require 'pdf/reader'
fileName = './storage/PDFs/docraptor-ruby.pdf'
PDF::Reader.open(fileName) do |reader|
@pdf_version = reader.pdf_version
# @producer = reader.producer
# @title = reader.title
@metadata = reader.metadata
@page_count = reader.page_count
end
end
def deletePDF
require 'fileutils'
FileUtils.rm_rf('./storage/PDFs/docraptor-ruby.pdf')
end
end
Penny for your thoughts? I'm on here for the rest of the evening, so I will be able to respond directly. Thank you for taking a look!
Cheers.
Controller: https://pastebin.com/QVaHCMep
Stack Trace: https://pastebin.com/uQbXgiaH
ruby-on-rails ruby model
ruby-on-rails ruby model
edited Mar 8 at 2:50
Antarr Byrd
10.1k2472126
10.1k2472126
asked Mar 8 at 0:05
ND GuthrieND Guthrie
11
11
A couple (or four) things. First, you should probably put the whole stack trace in your question (it's often easier to get a sense of the error and where it might be coming from). Second, IMO you are significantly overloading the responsibility of that model. Third, it seems strange to have thoserequire
statements sprinkled throughout (and configure statements, too). Fourth, and finally, it looks like a global variable in there ($docraptor
) which might not be a big deal but I personally never use.
– jvillian
Mar 8 at 0:29
Where is the code where you are actually initializing the model and saving it? Post it here please. And you should probably remove the comments in your code here, doesn't really help us to solve your problem.
– Antarr Byrd
Mar 8 at 0:51
Hello - Thanks for the response. I am self-taught with respect to Ruby and Rails, so I am always learning. Some of the apparent globals ($docraptor) were in some of the documentation, but I will take it under advisement. Some things seemed to break when I left requires in the higher level of the class, but I will double check. Should some of this be in the controller? I was building this under the guidelines of a "thin controller" model. I'm not sure if that's best though. Comments have been removed accordingly. Thank you for your help!
– ND Guthrie
Mar 8 at 1:57
Heroku app: murmuring-chamber-54696.herokuapp.com
– ND Guthrie
Mar 8 at 2:00
I would advise opening rails console and trying to save a record with the same attributes you'd get from the controller. If there's an error look at the stack trace to determine what line it originated from. I'm afraid without this info this question is impossible to answer. I'm assuming that since you can call@url_data_model.save
you have already initialized the record without error. None of the other model code actually gets run with the code you've shown
– max pleaner
Mar 8 at 9:53
|
show 1 more comment
A couple (or four) things. First, you should probably put the whole stack trace in your question (it's often easier to get a sense of the error and where it might be coming from). Second, IMO you are significantly overloading the responsibility of that model. Third, it seems strange to have thoserequire
statements sprinkled throughout (and configure statements, too). Fourth, and finally, it looks like a global variable in there ($docraptor
) which might not be a big deal but I personally never use.
– jvillian
Mar 8 at 0:29
Where is the code where you are actually initializing the model and saving it? Post it here please. And you should probably remove the comments in your code here, doesn't really help us to solve your problem.
– Antarr Byrd
Mar 8 at 0:51
Hello - Thanks for the response. I am self-taught with respect to Ruby and Rails, so I am always learning. Some of the apparent globals ($docraptor) were in some of the documentation, but I will take it under advisement. Some things seemed to break when I left requires in the higher level of the class, but I will double check. Should some of this be in the controller? I was building this under the guidelines of a "thin controller" model. I'm not sure if that's best though. Comments have been removed accordingly. Thank you for your help!
– ND Guthrie
Mar 8 at 1:57
Heroku app: murmuring-chamber-54696.herokuapp.com
– ND Guthrie
Mar 8 at 2:00
I would advise opening rails console and trying to save a record with the same attributes you'd get from the controller. If there's an error look at the stack trace to determine what line it originated from. I'm afraid without this info this question is impossible to answer. I'm assuming that since you can call@url_data_model.save
you have already initialized the record without error. None of the other model code actually gets run with the code you've shown
– max pleaner
Mar 8 at 9:53
A couple (or four) things. First, you should probably put the whole stack trace in your question (it's often easier to get a sense of the error and where it might be coming from). Second, IMO you are significantly overloading the responsibility of that model. Third, it seems strange to have those
require
statements sprinkled throughout (and configure statements, too). Fourth, and finally, it looks like a global variable in there ($docraptor
) which might not be a big deal but I personally never use.– jvillian
Mar 8 at 0:29
A couple (or four) things. First, you should probably put the whole stack trace in your question (it's often easier to get a sense of the error and where it might be coming from). Second, IMO you are significantly overloading the responsibility of that model. Third, it seems strange to have those
require
statements sprinkled throughout (and configure statements, too). Fourth, and finally, it looks like a global variable in there ($docraptor
) which might not be a big deal but I personally never use.– jvillian
Mar 8 at 0:29
Where is the code where you are actually initializing the model and saving it? Post it here please. And you should probably remove the comments in your code here, doesn't really help us to solve your problem.
– Antarr Byrd
Mar 8 at 0:51
Where is the code where you are actually initializing the model and saving it? Post it here please. And you should probably remove the comments in your code here, doesn't really help us to solve your problem.
– Antarr Byrd
Mar 8 at 0:51
Hello - Thanks for the response. I am self-taught with respect to Ruby and Rails, so I am always learning. Some of the apparent globals ($docraptor) were in some of the documentation, but I will take it under advisement. Some things seemed to break when I left requires in the higher level of the class, but I will double check. Should some of this be in the controller? I was building this under the guidelines of a "thin controller" model. I'm not sure if that's best though. Comments have been removed accordingly. Thank you for your help!
– ND Guthrie
Mar 8 at 1:57
Hello - Thanks for the response. I am self-taught with respect to Ruby and Rails, so I am always learning. Some of the apparent globals ($docraptor) were in some of the documentation, but I will take it under advisement. Some things seemed to break when I left requires in the higher level of the class, but I will double check. Should some of this be in the controller? I was building this under the guidelines of a "thin controller" model. I'm not sure if that's best though. Comments have been removed accordingly. Thank you for your help!
– ND Guthrie
Mar 8 at 1:57
Heroku app: murmuring-chamber-54696.herokuapp.com
– ND Guthrie
Mar 8 at 2:00
Heroku app: murmuring-chamber-54696.herokuapp.com
– ND Guthrie
Mar 8 at 2:00
I would advise opening rails console and trying to save a record with the same attributes you'd get from the controller. If there's an error look at the stack trace to determine what line it originated from. I'm afraid without this info this question is impossible to answer. I'm assuming that since you can call
@url_data_model.save
you have already initialized the record without error. None of the other model code actually gets run with the code you've shown– max pleaner
Mar 8 at 9:53
I would advise opening rails console and trying to save a record with the same attributes you'd get from the controller. If there's an error look at the stack trace to determine what line it originated from. I'm afraid without this info this question is impossible to answer. I'm assuming that since you can call
@url_data_model.save
you have already initialized the record without error. None of the other model code actually gets run with the code you've shown– max pleaner
Mar 8 at 9:53
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054793%2fmodel-initialization-passing-parameters-rails-5%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054793%2fmodel-initialization-passing-parameters-rails-5%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
A couple (or four) things. First, you should probably put the whole stack trace in your question (it's often easier to get a sense of the error and where it might be coming from). Second, IMO you are significantly overloading the responsibility of that model. Third, it seems strange to have those
require
statements sprinkled throughout (and configure statements, too). Fourth, and finally, it looks like a global variable in there ($docraptor
) which might not be a big deal but I personally never use.– jvillian
Mar 8 at 0:29
Where is the code where you are actually initializing the model and saving it? Post it here please. And you should probably remove the comments in your code here, doesn't really help us to solve your problem.
– Antarr Byrd
Mar 8 at 0:51
Hello - Thanks for the response. I am self-taught with respect to Ruby and Rails, so I am always learning. Some of the apparent globals ($docraptor) were in some of the documentation, but I will take it under advisement. Some things seemed to break when I left requires in the higher level of the class, but I will double check. Should some of this be in the controller? I was building this under the guidelines of a "thin controller" model. I'm not sure if that's best though. Comments have been removed accordingly. Thank you for your help!
– ND Guthrie
Mar 8 at 1:57
Heroku app: murmuring-chamber-54696.herokuapp.com
– ND Guthrie
Mar 8 at 2:00
I would advise opening rails console and trying to save a record with the same attributes you'd get from the controller. If there's an error look at the stack trace to determine what line it originated from. I'm afraid without this info this question is impossible to answer. I'm assuming that since you can call
@url_data_model.save
you have already initialized the record without error. None of the other model code actually gets run with the code you've shown– max pleaner
Mar 8 at 9:53