ruby-on-rails-3

Multiple Elasticsearch Indexes

老子叫甜甜 提交于 2019-12-24 10:46:50
问题 I have a staging & production instance of a Rails 3 application (using the tire gem) on the same Ubuntu server. It appears that both of these instances are sharing the same elasticsearch index which obviously isn't what I want. How can I get my production and staging instances to use separate instances? 回答1: You need override the index name. Assuming you're tying into ActiveRecord it will create an index name based on the model in question. You could adjust the name with a prefix like so;

Russian doll caching in rails

家住魔仙堡 提交于 2019-12-24 10:45:05
问题 I've heard DHH and the other great 37Signal guys talk a lot about Russian Doll Caching and I understand the concept of it, but I don't really know how to apply it to my code. How would you apply it? NEW EDIT: How would you apply the gem to a piece of code with a lot of if statements? <% if signed_in? %> <div class="timeline"> <%= link_to image_tag(current_user.avatar), designer_path(current_user), :class => "avatar topimg" %> <%= content_tag(:span, "your profile", :class => "description") %>

Overriding default Rails date_select

那年仲夏 提交于 2019-12-24 10:39:04
问题 So what I'd like to do is to override the default date_select method (I'd like to make an 'optional / unspecified' date input). What I've tried so far is this: lib/overrides.rb ActionView::Helpers::DateHelper::DateTimeSelector.class_eval do def build_selects_from_types(order) select = '' order.reverse.each do |type| separator = separator(type) unless type == order.first # don't add on last field select.insert(0, separator.to_s + send("select_#{type}").to_s) end select.insert(0, '<p>HI!!</p>')

Rails 3 Resource routing for join models

别来无恙 提交于 2019-12-24 10:38:06
问题 I have a many-to-many relationship between users and teams (as a has_many :through), and I'm trying to setup a "team members" join model as a resource in the routes. In my layouts I've setup a "team context form" that sets a session variable for the current_team , and I want the route for the team_members resources to be defined as /team_members/:user_id/show . Is there any way to do this with the resources :team_members in routes.rb? I've tried using :path_names => {:action => "\some\url"} ,

Ruby on Rails: “no such file or directory” with logger.rb

浪子不回头ぞ 提交于 2019-12-24 10:37:25
问题 I'm attempting to run a RoR app locally for the first time. I've started the server and I get the following error (after WEBrick starts): C:/Ruby/lib/ruby/1.9.1/logger.rb:599:in `initialize': No such file or directory - /dev/null (Errno::ENOENT) I try to run rake db:migrate and I get the same error: ** Execute environment rake aborted! No such file or directory - /dev/null C:/Ruby/lib/ruby/1.9.1/logger.rb:599:in `initialize' C:/Ruby/lib/ruby/1.9.1/logger.rb:599:in `open' C:/Ruby/lib/ruby/1.9

If you modify code in the Rails console will that affect a server running in parallel?

橙三吉。 提交于 2019-12-24 10:35:35
问题 Is it possible to run "rails console" in one shell and then "rails server" in another and then have code changes in the console permeate to the running application? Presumably this isn't possible, but I'd just like to check if there is a way. Edit: Both are running in the same environment. And by code changes I mean changes to class definitions (e.g. rewriting a method on the Post model). 回答1: If you modify any data, that will indeed permeate. However modifications to methods done on the fly

Any idea not to select the name that is already chosen in token input?

…衆ロ難τιáo~ 提交于 2019-12-24 10:11:28
问题 Is there any idea not to select the name that is already chosen in token input? For example In first I select mango when I search for m. Next time again when I search for m Mango should not be displayed as mango is already chosen. Is there any idea? <%= f.text_field :plan_tokens, data: {load: @customer.plans} %> I have my js like this jQuery -> $('#customer_plan_tokens').tokenInput '/plans.json' theme: 'facebook' prePopulate: $('#customer_plan_tokens').data('load') where to put

Best way to duplicate parent and associated child records in Ruby on Rails? [duplicate]

大兔子大兔子 提交于 2019-12-24 10:03:03
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: ActiveRecord: How can I clone nested associations? I have a table with invoices which in turn can have many items . Now in my invoices index view I would like to place a link next to each invoice saying Duplicate Invoice . Without the child records this would be quite easy: <%= link_to "Duplicate", new_invoice_path(invoice.attributes) %> But how can this be done if the invoice's items should be duplicated as

Running rails generate scaffold does not generate model

丶灬走出姿态 提交于 2019-12-24 09:58:45
问题 If I type (copy / paste exactly from "rails g scaffold --help") rails generate scaffold purchase amount:decimal tracking_id:integer:uniq Then the controller is created, views, the model is created.. but it contains no properties. It literally contains: class Purchase < ActiveRecord::Base end Am I missing something? Versions Rails 3.2.0 ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] Mac OSX Lion 回答1: That's actually right. Normally if you were making some random Ruby program and

Creating a Rails partial that is model-agnostic

时光怂恿深爱的人放手 提交于 2019-12-24 09:58:07
问题 I have the two Ruby on Rails models SafetyTest and TeamDue , and want to create a partial called _seasonal.html.erb that can work with either models. The real problem is adding a link to create a new instance. For example, it would be this code for just SafetyTest : <%= link_to new_safety_test_path %> Now I want to be able to specify in my view, when I'm rendering _seasonal.html.erb , whether I want such a link for SafetyTest or TeamDue . I'm not sure what local to pass to this partial so