ruby-on-rails-3

Matching nested model association attribute with includes

…衆ロ難τιáo~ 提交于 2020-01-02 04:08:31
问题 Suppose I have the following models: class Post < ActiveRecord::Base has_many :authors class Author < ActiveRecord::Base belongs_to :post And suppose the Author model has an attribute, name . I want to search for all posts with a given author "alice", by that author's name. Say there is another author "bob" who co-authored a post with alice. If I search for the first result using includes and where : post = Post.includes(:authors).where("authors.name" => "alice").first You'll see that the

What's the easiest way, to post on my Facebook Wall through my Ruby on Rails App?

风流意气都作罢 提交于 2020-01-02 03:39:14
问题 last week, I integrated successfully twitter with my "small" rails app. If I create a new record in my rails app it will be posted on twitter. But how Do I do this with facebook? Twitter was really easy (thanks to the Twitter gem) Can you recommend a gem? A link to an example app would also be nice. Thanks in advance cheers tabaluga p.s. Oh, I forgot to mention, I do not have a personal facebook account. The Facebook Wall is a Company site. 回答1: I am using fb_graph and I really like it, very

Reopening Rails 3 engine classes from parent app

余生长醉 提交于 2020-01-02 03:27:08
问题 As it stands now, you can't reopen Engine classes contained within the engine's /app directory by simply adding the same class in the parent app's /app dir. For example: /my_engine/app/controllers/users_controller.rb /my_app/app/controllers/users_controller.rb The file from my_engine will not even load if there is a file with the same name in the parent app. More details here: http://www.cowboycoded.com/2011/02/28/why-you-cant-reopen-rails-3-engine-classes-from-the-parent-app/ I am looking

Multiple files uploading on Ruby on Rails 3 [closed]

断了今生、忘了曾经 提交于 2020-01-02 02:26:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I would like to upload multiple pictures to my Rails 3 application. I am currently using Paperclip to upload a picture, and I have some post processing operations assigned to the model Photo. I saw some samples on the net (integrating uploadify, swfupload or some other libraries), but none was very detailed, and

Rails 3 and will_paginate - elegant way, how to get total_pages

ぃ、小莉子 提交于 2020-01-02 02:01:48
问题 I am working with will_paginate plugin in Rails 3 and I am trying to get to some variable the count of pages (total_pages). I thought the total pages is in globally variable @total_pages , or in @option[:total_pages]**, but if I will use this variables in my view, so it don't work. I know, I can get the total pages of my items in DB table separately by this plugin, but couldn't be so elegant, if I will have that value already stored in some variable by plugin... So I would like to ask you -

Multiple database tables within one AR model in Rails 3

会有一股神秘感。 提交于 2020-01-02 02:01:10
问题 I was asked to make some kind of reporting (logging) service. The employee has locally installed web application (just some dynamic website, written in PHP) in many companies. This web app is some kind of survey. All data is saved on local database, but now the requirement is that this data (result of survey) will also be sent to central server after every form submit. There are four types of surveys. They have organised it this way, that there are many Projects, and each Project can have

Rails, Why does this helper not output HTML, but rather HTML in quotes?

风流意气都作罢 提交于 2020-01-02 01:58:10
问题 I have the following helper in my application_helper.rb file: def topmenu pages = { "projects" => projects_path, "photos" => photos_path } pages.map do |key, value| classnames = %( class="current") if controller.controller_name == key "<li#{classnames}>#{link_to(key, value)}</li>" end end Then in my application.html.erb file I have: <%= topmenu %> For some reason, the page is generating showing the HTML from the above helper as TEXT, not HTML. Not sure why? thx 回答1: I presume you're running

superclass mismatch for class CommentsController (TypeError), best way to rename?

家住魔仙堡 提交于 2020-01-02 01:41:11
问题 I ran into some problem tonight while deploying and I'm trying to get this fixed asap I have no idea why this is happening. Everything works fine locally but not on heroku. I tried all sorts of different fixes after researching but I may have to resort to renaming this class CommentsController completely (hopefully that works). What is the best way to go about that? I'm pretty new to Rails so I need some help on making these changing correctly. Here's what the CommentsController looks like

How do you solve FixtureClassNotFound: No class attached to find

丶灬走出姿态 提交于 2020-01-02 01:04:14
问题 When running my tests I get this error: FixtureClassNotFound: No class attached to find What causes this error and how to fix it? 回答1: Most likely this happens because a custom table name is used for a Model (using the set_table_name) or the model is in a module. To solve, you need to add a set_fixture_class line in the test_helper.rb before the fixtures :all line: class ActiveSupport::TestCase self.use_transactional_fixtures = true . . . set_fixture_class my_table_name: MyModule::MyClass

Redis::CommandError: ERR Client sent AUTH, but no password is set

余生长醉 提交于 2020-01-02 01:02:32
问题 This has to be some wrong config I installed redis on localhost. When trying to connect to it through Rails console Redis.new(:host => 'localhost', :port => 6379) I can't send commands and I get Redis::CommandError: ERR Client sent AUTH, but no password is set I don't recall setting a password, nor do I know where to see if a password has been set if I use a different URL (like rediscloud or redistogo) I can send commands (setting the password accodingly) From what I understand the error says