Ruby on Rails Saturday, September 4, 2010

Hello all,

for some reason nothing is being inserted into the database. I have no
idea why not! Here is my action:

def create
@information = CalorieKing.new
@information = CalorieKing.get_information(params[:id])
@information = @information['food']['servings']
@information['serving'].each do |s|
if s['name'] == params[:portion_type]
s['nutrients'].each do |value|
value *= params[:size]
end
puts 'hello'
@foodentry = FoodEntry.new(:user_id => current_user.id,
:name => s['name'], :serving_size => params[:size],
:serving_name => params[:portion_type], :calories =>
s['nutrients']['caloires'],
:fat => s['nutrients']['fat'], :carbs => s['nutrients']['carb'],
:protein => s['nutrients']['protein'], :fiber =>
s['nutrients']['fiber'],
:sugar => s['nutrients']['sugar'], :sodium =>
s['nutrients']['sodium'],
:calcium => s['nutrients']['calcium'], :satfat =>
s['nutrients']['satfat'],
:cholesterol => s['nutrients']['cholesterol'])
@foodentry.save
puts 'hello'
end
end
respond_to do |format|
format.html { redirect_to(food_diary_path) }
format.xml { head :ok }
end
end

Thanks!
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment