ruby-on-rails-3.1

simple Ruby Input and Output Exercise log [duplicate]

自古美人都是妖i 提交于 2019-12-11 23:42:08
问题 This question already has an answer here : How do I create this File Input and Output assignment in Ruby (1 answer) Closed 6 years ago . I have a project in my programming class. This is my assignment: Create a program that allows the user to input how many hours they exercised for today. Then the program should output the total of how many hours they have exercised for all time. To allow the program to persist beyond the first run the total exercise time will need to be written and retrieved

How to save values of a JSON response in a rails database?

白昼怎懂夜的黑 提交于 2019-12-11 21:52:34
问题 I want to access the Facebook Graph API and get JSON responses like this: { "data": [ { "name": "Coldplay", "category": "Musician/band", "id": "15253175252", "created_time": "2012-01-27T22:51:44+0000" }, { "name": "R.E.M.", "category": "Musician/band", "id": "8759772983", "created_time": "2012-01-27T22:51:43+0000" } ], "paging": { "next": "https://graph.facebook.com/1000032123447/music?format=json&limit=5000&offset=5000&__after_id=8123918" } } Now I want to save the name, the category and id

Stylesheet Error - Ruby on Rails Newbie

核能气质少年 提交于 2019-12-11 20:08:53
问题 I am currently learning ruby on rails through "Agile Web Development With Rails," and I have run into an error I cannot fix. So far, I have only done some basic operations. I created a scaffold with a command similar to this: rails generate scaffold Product title:string description:text image_url:string price:decimal I then raked that: rake db:migrate Once that was run, I went into the db/seeds.db file and filled this newly created table with this data: Product.delete_all Product.create(

Rails 3.1 Dependent / Cascading Dropdowns

馋奶兔 提交于 2019-12-11 19:32:26
问题 I am getting to grips with Rails 3.1, and I am hoping that someone can point me in the direction of a Gem that will allow me to use dependent selects on a form (or indicate how this is best done in Rails 3.1). I have come across the chained_selects plugin, but that seems to rely on prototype, so it is not ideal in 3.1. The simplest example of this is car makes/models: I have 3 models: vehicleMake, vehicleModel and vehicleTrim. I also have assignment tables vehicleMake_vehicleModel and

No method error when trying to call a function with an instantiated object

只愿长相守 提交于 2019-12-11 19:16:21
问题 I have a model Token with three fields user_id,product_id and unique_token .In the controller i instantiate a @token object with user_id and product_id values collected from the form.Then i call save_with_payment function with that object,where within the function i want to generate random string 3 times and save in unique_token field .The problem is self.tokens.create!( unique_token: Digest::SHA1.hexdigest("random string") ) give me no method error undefined method tokens .What am i doing

How to generate create table migration file using Rails::Generators.invoke(“active_record:migration”)?

吃可爱长大的小学妹 提交于 2019-12-11 18:42:13
问题 When I used this code Rails::Generators.invoke("active_record:migration","create_tests",{:behavior=>:invoke, :destination_root=>Rails.root}) to generate migration file, I got the following class generated: class CreateTests < ActiveRecord::Migration def up end def down end end But what I want is this: class CreateTests < ActiveRecord::Migration def change create_table :tests do |t| t.timestamps end end end I'm not aware of what parameters I need to pass inside the invoke method. 回答1: You can

Why am I getting a “Could not find table 'users'” error?

强颜欢笑 提交于 2019-12-11 18:34:21
问题 I'm relatively new to Rails and I've been getting the above error whenever I'm testing my login page. Here's the test view file: <%= form_for :user, :url => create_path do |f| %> <p> Email: <br /> <%= f.text_field :email %></p> <p> Password: <br /> <%= f.password_field :password %></p> <p><%= submit_tag "Sign In", :disable_with => "Please wait...", :class => "btn primary" %></p> <% end %> Here's the Users controller: class UsersController < ApplicationController before_filter :get_user,

Ruby rails s error

跟風遠走 提交于 2019-12-11 18:26:58
问题 I'm getting this massive error when I try to run rails s , I've just re installed ruby as well as PostgreSQL. Thanks for help. This was right after I ran rails s also, i've made a other post on similar issues if that helpes at all in any way possible Rails Forem installation assistance i'm still really new with Ruby just to keep that in mind. thanks again. ERROR: => Booting WEBrick => Rails 3.2.11 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C

Association Ruby on Rails

前提是你 提交于 2019-12-11 18:26:44
问题 I am trying a an simple association which should work. I followed the tutorial at http://ruby.railstutorial.org/chapters/ and at chapter 10 Here what I have wrote down model/customer class Customer < ActiveRecord::Base has_many :posts, dependent: :destroy attr_accessible :name, :email, :password, :password_confirmation has_secure_password model/post class Post < ActiveRecord::Base belongs_to :customer attr_accessible :description, :post_finish_at, :post_how, :post_location controller

Rails error: object does not support #inspect

心已入冬 提交于 2019-12-11 16:44:56
问题 Scratching my head here... If I try the following with rails: User.limit(25).includes([:addresses]) I get: User Load (109.5ms) EXEC sp_executesql N'SELECT TOP (25) [User].* FROM [User]' Address Load (112.3ms) EXEC sp_executesql N'SELECT [Address].* FROM [Address] WHERE [Address].[UserId] IN (N''1'', N''2'', N''3'', N''6'', N''7'', N''8'', N''9'', N''11'', N''12'', N''16'', N''17'', N''18'', N''19'', N''20'', N''21'', N''22'', N''24'', N''25'', N''26'', N''27'', N''28'', N''29'', N''30'', N'