Trying to save api data to my database, @headline not being populated for tabledynamic nested form always creates an extra blank entry - using formtastic_coocoonruby on rails has_many relation form validation of childrenAjax submissions with jquery in rails not workingIssues with Rails 3.1 API with Query String to Create action on Mac OSX Mountain LionRoute failing using STIRails 3.2.8 form_for submit button is using the 'new' action instead of 'create' actionRails 4 Form Data Is Saving as Nilundefined method `people_path' for #<#<Class:0x007f4bcc6bbbf0>:0x000000023b70c0>Rails Dot in Url with two routes for one controllerredirect_to an instance variable does not work in Rails 4
How did the SysRq key get onto modern keyboards if it's rarely used?
Can Papyrus be folded?
How can Paypal know my card is being used in another account?
What language is Raven using for her attack in the new 52?
If the Moon were impacted by a suitably sized meteor, how long would it take to impact the Earth?
Scam? Checks via Email
What are the cons of stateless password generators?
Why would an invisible personal shield be necessary?
Wrapping IMemoryCache with SemaphoreSlim
Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?
Why is softmax function used to calculate probabilities although we can divide each value by the sum of the vector?
Is there a word to describe someone who is, or the state of being, content with hanging around others without interacting with them?
Can I attune a Circlet of Human Perfection to my animated skeletons to allow them to blend in and speak?
Is it okay for me to decline a project on ethical grounds?
How to season a character?
What would the United Kingdom's "optimal" Brexit deal look like?
Semen retention is a important thing in Martial arts?
Complexity of verifying optimality in (mixed) integer programming
Why force the nose of 737 Max down in the first place?
GNU GPL V3 with no code change disclosure
90s/2000s TV show : man uses government time machine to fix national problems
Is The Venice Syndrome documentary cover photo real?
How do I say "this is why…"?
How does a poisoned arrow combine with the spell Conjure Barrage?
Trying to save api data to my database, @headline not being populated for table
dynamic nested form always creates an extra blank entry - using formtastic_coocoonruby on rails has_many relation form validation of childrenAjax submissions with jquery in rails not workingIssues with Rails 3.1 API with Query String to Create action on Mac OSX Mountain LionRoute failing using STIRails 3.2.8 form_for submit button is using the 'new' action instead of 'create' actionRails 4 Form Data Is Saving as Nilundefined method `people_path' for #<#<Class:0x007f4bcc6bbbf0>:0x000000023b70c0>Rails Dot in Url with two routes for one controllerredirect_to an instance variable does not work in Rails 4
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to save news data for stocks from an api to my "Headline" database. But I think my controller params are wrong and so I can't populate an item to save to my table.
I've tried changing the @headline = Headline.new_from_lookup(params[:stock]) params to :ticker :symbol but nothing changes. Still getting undefined method `save' for nil:NilClass
Routes.rb
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
root 'headlines#new'
resources :headlines
end
headline.rb
class Headline < ActiveRecord::Base
require 'iex-ruby-client'
def self.new_from_lookup(symbol)
begin
looked_up_stock = IEX::Resources::Quote.get(symbol)
looked_up_news = IEX::Resources::News.get(symbol)
new(ticker: looked_up_stock.symbol, name: looked_up_stock.companyName, headline: looked_up_news.first.headline, summary: looked_up_news.first.summary, url: looked_up_news.first.url)
rescue Exception => e
return nil
end
end
end
headline_controller.rb
class HeadlinesController < ApplicationController
def new
@headline = Headline.new
end
def create
# takes input from the search page then finds the stock info with the model headline.rb
@headline = Headline.new_from_lookup(params[:symbol])
@headline.save # saves the headline info to the database
redirect_to headline_path(@headline) # directs the user to the show path
end
def show
@headline = Headline.find(params[:id]) # shows the news from the database that was just entered
end
end
new.html.erb
<h1>Choose Stock News</h1>
<%= form_for @headline do |f| %>
<p>
<%= f.label :ticker %>
<%= f.text_field :ticker %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
</body>
show.html.erb
Showing Selected Stock News
Ticker:
Name:
Headline:
Summary:
Url:
Created:
Updated:
ruby-on-rails ruby api
add a comment |
I'm trying to save news data for stocks from an api to my "Headline" database. But I think my controller params are wrong and so I can't populate an item to save to my table.
I've tried changing the @headline = Headline.new_from_lookup(params[:stock]) params to :ticker :symbol but nothing changes. Still getting undefined method `save' for nil:NilClass
Routes.rb
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
root 'headlines#new'
resources :headlines
end
headline.rb
class Headline < ActiveRecord::Base
require 'iex-ruby-client'
def self.new_from_lookup(symbol)
begin
looked_up_stock = IEX::Resources::Quote.get(symbol)
looked_up_news = IEX::Resources::News.get(symbol)
new(ticker: looked_up_stock.symbol, name: looked_up_stock.companyName, headline: looked_up_news.first.headline, summary: looked_up_news.first.summary, url: looked_up_news.first.url)
rescue Exception => e
return nil
end
end
end
headline_controller.rb
class HeadlinesController < ApplicationController
def new
@headline = Headline.new
end
def create
# takes input from the search page then finds the stock info with the model headline.rb
@headline = Headline.new_from_lookup(params[:symbol])
@headline.save # saves the headline info to the database
redirect_to headline_path(@headline) # directs the user to the show path
end
def show
@headline = Headline.find(params[:id]) # shows the news from the database that was just entered
end
end
new.html.erb
<h1>Choose Stock News</h1>
<%= form_for @headline do |f| %>
<p>
<%= f.label :ticker %>
<%= f.text_field :ticker %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
</body>
show.html.erb
Showing Selected Stock News
Ticker:
Name:
Headline:
Summary:
Url:
Created:
Updated:
ruby-on-rails ruby api
Can you modify the post. It is hard to read, it would make it easier if you use the tools to insert code snippets.
– Steven Aguilar
Mar 26 at 21:19
add a comment |
I'm trying to save news data for stocks from an api to my "Headline" database. But I think my controller params are wrong and so I can't populate an item to save to my table.
I've tried changing the @headline = Headline.new_from_lookup(params[:stock]) params to :ticker :symbol but nothing changes. Still getting undefined method `save' for nil:NilClass
Routes.rb
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
root 'headlines#new'
resources :headlines
end
headline.rb
class Headline < ActiveRecord::Base
require 'iex-ruby-client'
def self.new_from_lookup(symbol)
begin
looked_up_stock = IEX::Resources::Quote.get(symbol)
looked_up_news = IEX::Resources::News.get(symbol)
new(ticker: looked_up_stock.symbol, name: looked_up_stock.companyName, headline: looked_up_news.first.headline, summary: looked_up_news.first.summary, url: looked_up_news.first.url)
rescue Exception => e
return nil
end
end
end
headline_controller.rb
class HeadlinesController < ApplicationController
def new
@headline = Headline.new
end
def create
# takes input from the search page then finds the stock info with the model headline.rb
@headline = Headline.new_from_lookup(params[:symbol])
@headline.save # saves the headline info to the database
redirect_to headline_path(@headline) # directs the user to the show path
end
def show
@headline = Headline.find(params[:id]) # shows the news from the database that was just entered
end
end
new.html.erb
<h1>Choose Stock News</h1>
<%= form_for @headline do |f| %>
<p>
<%= f.label :ticker %>
<%= f.text_field :ticker %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
</body>
show.html.erb
Showing Selected Stock News
Ticker:
Name:
Headline:
Summary:
Url:
Created:
Updated:
ruby-on-rails ruby api
I'm trying to save news data for stocks from an api to my "Headline" database. But I think my controller params are wrong and so I can't populate an item to save to my table.
I've tried changing the @headline = Headline.new_from_lookup(params[:stock]) params to :ticker :symbol but nothing changes. Still getting undefined method `save' for nil:NilClass
Routes.rb
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
root 'headlines#new'
resources :headlines
end
headline.rb
class Headline < ActiveRecord::Base
require 'iex-ruby-client'
def self.new_from_lookup(symbol)
begin
looked_up_stock = IEX::Resources::Quote.get(symbol)
looked_up_news = IEX::Resources::News.get(symbol)
new(ticker: looked_up_stock.symbol, name: looked_up_stock.companyName, headline: looked_up_news.first.headline, summary: looked_up_news.first.summary, url: looked_up_news.first.url)
rescue Exception => e
return nil
end
end
end
headline_controller.rb
class HeadlinesController < ApplicationController
def new
@headline = Headline.new
end
def create
# takes input from the search page then finds the stock info with the model headline.rb
@headline = Headline.new_from_lookup(params[:symbol])
@headline.save # saves the headline info to the database
redirect_to headline_path(@headline) # directs the user to the show path
end
def show
@headline = Headline.find(params[:id]) # shows the news from the database that was just entered
end
end
new.html.erb
<h1>Choose Stock News</h1>
<%= form_for @headline do |f| %>
<p>
<%= f.label :ticker %>
<%= f.text_field :ticker %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
</body>
show.html.erb
Showing Selected Stock News
Ticker:
Name:
Headline:
Summary:
Url:
Created:
Updated:
ruby-on-rails ruby api
ruby-on-rails ruby api
asked Mar 26 at 20:41
Mark ShffMark Shff
82 bronze badges
82 bronze badges
Can you modify the post. It is hard to read, it would make it easier if you use the tools to insert code snippets.
– Steven Aguilar
Mar 26 at 21:19
add a comment |
Can you modify the post. It is hard to read, it would make it easier if you use the tools to insert code snippets.
– Steven Aguilar
Mar 26 at 21:19
Can you modify the post. It is hard to read, it would make it easier if you use the tools to insert code snippets.
– Steven Aguilar
Mar 26 at 21:19
Can you modify the post. It is hard to read, it would make it easier if you use the tools to insert code snippets.
– Steven Aguilar
Mar 26 at 21:19
add a comment |
1 Answer
1
active
oldest
votes
Instead of
rescue Exception => e
return nil
end
write
rescue Exception => e
puts e.message
puts e.stacktrace.join("n")
return nil
end
at least you can see what error you have
plus in controller you need to check later if object is nil
add a comment |
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%2f55365868%2ftrying-to-save-api-data-to-my-database-headline-not-being-populated-for-table%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Instead of
rescue Exception => e
return nil
end
write
rescue Exception => e
puts e.message
puts e.stacktrace.join("n")
return nil
end
at least you can see what error you have
plus in controller you need to check later if object is nil
add a comment |
Instead of
rescue Exception => e
return nil
end
write
rescue Exception => e
puts e.message
puts e.stacktrace.join("n")
return nil
end
at least you can see what error you have
plus in controller you need to check later if object is nil
add a comment |
Instead of
rescue Exception => e
return nil
end
write
rescue Exception => e
puts e.message
puts e.stacktrace.join("n")
return nil
end
at least you can see what error you have
plus in controller you need to check later if object is nil
Instead of
rescue Exception => e
return nil
end
write
rescue Exception => e
puts e.message
puts e.stacktrace.join("n")
return nil
end
at least you can see what error you have
plus in controller you need to check later if object is nil
answered Mar 26 at 21:54
Igor KasyanchukIgor Kasyanchuk
5873 silver badges10 bronze badges
5873 silver badges10 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55365868%2ftrying-to-save-api-data-to-my-database-headline-not-being-populated-for-table%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
Can you modify the post. It is hard to read, it would make it easier if you use the tools to insert code snippets.
– Steven Aguilar
Mar 26 at 21:19