ruby-on-rails-3.2

Adding a custom seed file

坚强是说给别人听的谎言 提交于 2019-12-29 02:29:04
问题 I want to populate a new feature with dummy data, but don't want to use the db/seeds.rb file as it already has seeds other data irrelevant for this feature. To run the default seeds.rb file, you run the command rake db:seed . If I create a file in the db directory called seeds_feature_x.rb , what would the rake command look like to run (only) that file? 回答1: Start by creating a separate directory to hold your custom seeds – this example uses db/seeds . Then, create a custom task by adding a

PostgreSQL Permission denied Error on Unix domain socket “/var/pgsql_socket/.s.PGSQL.5432” - Lion Server 10.7.3 or Lion Server 10.7.4

喜你入骨 提交于 2019-12-29 01:47:11
问题 I recently had major permission problems using Lion Server where permissions would change on folders at will. During this time I had started getting the following error when trying to do a rake db:migrate command: rake aborted! could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? This had been working before when I first created a Rails 3.2.3 application while running 10.7.2. All of a

Call a controller method automatically when rendering a partial

假如想象 提交于 2019-12-25 11:34:52
问题 I have a partial that needs to have some controller logic run before it can render without issue. Is there some way to associate the partial with some controller logic that is run whenever it is rendered? For example, this is what my current code looks like: MyDataController: class MyDataController < ApplicationController def view @obj = MyData.find(params[:id]) run_logic_for_partial end def some_method_i_dont_know_about @obj = MyData.find(params[:id]) # Doesn't call run_logic_for_partial end

Unable to add Impressionist model to Solr

℡╲_俬逩灬. 提交于 2019-12-25 08:03:23
问题 To keep track of unique views I added impressionist gem. The impressions table will grow at a faster rate due to higher traffic. This will cause problems later when I want to show a comparison between consecutive weeks/months. So I thought of linking impression's model with solr . To implement this I first created a model named impression under app/models/impression.rb folder. class Impression < ActiveRecord::Base attr_accessible :user_id, :ip_address, :action_name, :controller_name,

How can I get the datatype of an attribute from a Rails model?

空扰寡人 提交于 2019-12-25 07:29:44
问题 I am using Postgres in a Rails project and I have discovered that I need to change all of my varchar datatypes to citext . Rather than do this by hand, I want to just create a migration that loops through all of the models and their attributes and converts them as necessary. Most of these models are empty, so it's not a matter of instantiating them. I need to find out if ActiveRecord "knows" what the datatype of its corresponding database column is. 回答1: @model.column_for_attribute('title')

Passing Multiple Parameters in a form_tag

久未见 提交于 2019-12-25 06:36:29
问题 I'm using Rails and jqPlot to display some data on a webpage. The graph needs to be flexible by date (as in, the user can select a time range, and the graph will update itself). Here's my code so far (in my View): <%= form_tag home_event_trends_path(params[:timePeriod]), :method => 'post' do %> <p> <%= select_tag :timePeriod, options_for_select(["2 Hours Ago", "1 Week Ago", "3 Months Ago"], :selected => params[:timePeriod]) %> <%= submit_tag "Refresh", :name => nil %> </p> <% end %> Home is

How to localize a generic error messages partial in Rails 3.2.3?

£可爱£侵袭症+ 提交于 2019-12-25 05:51:39
问题 I am using the following partial to display error messages for most of my models in Rails 3.2.3: # _error_messages.html.erb <% if object.errors.any? %> <div id="error_explanation"> <h3><%= pluralize(object.errors.count, "error") %> prohibited this <%= object.class.to_s.underscore.humanize.downcase %> from being saved:</h3> <p>There were problems with the following fields:</p> <ul> <% object.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> This worked

Run Generate Controller command from a Module

一笑奈何 提交于 2019-12-25 05:24:41
问题 I know the basic command to create controllers in Rails is to use Rails generate controller But in the code I see something like this structure below and was wondering how to do that? The structure looks like this: and the generated code looks like this, I need something similar: module Performance class BaseController < ApplicationController end end module Performance class GroupsController < BaseController def show end def index end end end 回答1: To generate namespaced controller you should

Rails 3.2.6: Getting 'Unable to access log file' error for development.log file

♀尐吖头ヾ 提交于 2019-12-25 05:22:51
问题 This seems like it would be a common problem, but I just can't seem to find the solution through google searches, etc. I just created a new Rails 3.2.6 application and configured it to use the PostgreSQL database for my local development. I followed this RailsCast and was able to get everything installed and set up correctly. However, whenever I try to do any rails generate or rake commands ( rails generate model , rake db:migrate etc), I get the following error referring to my development

Getting error PDF could not generated in Rails 3

走远了吗. 提交于 2019-12-25 03:34:33
问题 I am getting the following error while converting the HTML file to PDF using wicked_pdf gem in Rails 3. error: Error: Failed to execute: ["C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe", "file://C:/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf20150526-648-17uza61.html", "C:/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf_generated_file20150526-648-w6l9ye.pdf"] Error: PDF could not be generated! Command Error: Loading pages (1/6) [> ] 0% [======> ] 10% Error: Failed loading page file://c/DOCUME