ruby-on-rails-3.2

How to require a ruby file from another directory

假装没事ソ 提交于 2020-01-09 06:20:32
问题 I am trying to require a rake file that I have created inside another file I have. These two files are inside two different directories. I have require at the top of my first file with the name of the second file inside the quotes after the require. It is telling me that it can't load such file. Does that mean because its in different directory it can't find it? I tried sticking in the full path to the second file but it still can't load the file. Does anyone know how I can load the second

How to require a ruby file from another directory

跟風遠走 提交于 2020-01-09 06:20:07
问题 I am trying to require a rake file that I have created inside another file I have. These two files are inside two different directories. I have require at the top of my first file with the name of the second file inside the quotes after the require. It is telling me that it can't load such file. Does that mean because its in different directory it can't find it? I tried sticking in the full path to the second file but it still can't load the file. Does anyone know how I can load the second

URI mismatch Rails generates MD5 digest in asset URL in production, but controller GET's a non-MD5 URL

蹲街弑〆低调 提交于 2020-01-06 19:37:18
问题 I have a Rails app with a page or two that uses the html5 video tag, and the corresponding Rails video_tag() method to display video on the page. I've added <%= video_tag "car_circle.mp4", width: "640", height: "500", controls: true %> to an html.erb file in views. Rails 3.2 looks for videos in the /public directory, and so I've added my videos to a folder called public/videos . In order to add this folder to the asset pipeline, I added this line to application.rb config.assets.paths << "#

create new object in rails3 using multimodel form

时光怂恿深爱的人放手 提交于 2020-01-06 19:37:12
问题 I am n00b as rails is concerned. I am trying yo create a single multimodel form in my first rails3 project. Details are given below: class Item < ActiveRecord::Base # attr_accessible :title, :body has_many :item_reviews, :dependent => :destroy accepts_nested_attributes_for :item_reviews end and class ItemReview < ActiveRecord::Base # attr_accessible :title, :body belongs_to :item end So as clear, an item can have multiple reviews but when I am creating an item, I want at least 1 review for it

Need to avoid SQL Injection in Rails3

荒凉一梦 提交于 2020-01-06 08:44:49
问题 I need the following code to be rewritten by avoiding SQL Injection in Rails 3. some_table_name.joins("inner join #{table_name} on linked_config_items.linked_type = '#{class_name}' and linked_config_items.linked_id = #{table_name}.id"). where("#{table_name}.saved is true and #{table_name}.deleted_at is null") Here, table_name is dynamic and it will vary. 回答1: SQL identifiers like table names and column names cannot be replaced with bound parameters, which is the more common method to ensure

How do I display select field values rather than their associated stored integers in ruby on rails?

孤街浪徒 提交于 2020-01-06 08:07:52
问题 Say for example I allow my users to select their gender and marital status in form and then post that form so their selections are stored in the database. A form could look like this: <select id="profile_marital_status" name="profile[marital_status]"><option value=""> Select</option> <option value="1">Single</option> <option value="2" selected="selected">Dating</option> <option value="3">In relationship</option> <option value="4">Married</option> <option value="5">Living Together</option>

Relation “translations” does not exist after migrating to Rails 3.2.1

断了今生、忘了曾经 提交于 2020-01-06 02:28:12
问题 I migrated from Rails 3.1.3 to 3.2.1 and got the following error when loading the home page: PGError: ERROR: relation "translations" does not exist LINE 4: WHERE a.attrelid = '"translations"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"translations"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum This happens when

accessing sub documents on Rails 3 using Mongoid

﹥>﹥吖頭↗ 提交于 2020-01-05 10:09:09
问题 Here you will find Ryan's railscast called Mongoid (revised) . I've created an app following the railscast and put it on https://github.com/tenzan/store.git In this example, product collection has embedded reviews . I was able to add reviews within from rails console and wanted to display on the browser, what I can't figure out. I feel like I have to tweak in the app/controllers/reviews_controller.rb and app/views/reviews/index.html.erb The app was created Rails 3 and ruby 1.9.3p429. Edit: I

How can I use Private Pub with a Resource Route that has a segment key?

自作多情 提交于 2020-01-05 08:16:28
问题 I'm currently having a problem while using Private Pub in a Rails 3 Project. All the examples show the usage of publish/subscribe to a route like this: "/messages/new" But What If the intended route is a little more complex, ie. routes.rb resources :messages, only: [] do post 'chat', on: :member end Which will create the following chat_message POST /messages/:id/chat(.:format) messages#chat Therefore, I'm using it like this: view: = subscribe_to "/messages/#{@cid}/chat" coffee response view:

update fail - undefined method `update_attributes' for #<ActiveRecord::Relation:

扶醉桌前 提交于 2020-01-05 07:13:25
问题 This follows on from my previous request which I answered. But my next issue which I cannot understand is why when my parameters report one record do I get a message that googling/SO searching suggest I need to use an update_all. has_many/belongs_to build association - why is insert statement for parameter blank? My update controller method is as follows: def update @role = Role.find(params[:id]) logger.debug "@role: id[#{params[:id]}], #{@role}, #{@role.inspect}, #{@role.to_s}" @permission =