ruby-on-rails-3

CSV not working for Rails 3 in Production using passenger

一世执手 提交于 2020-01-04 01:58:08
问题 I currently have a problem where i am exporting some data and generating a CSV in rails3. In my controller i add the following at the top. require 'CSV' I then have my method that generates the CSV file. In development i am able to generate and download the csv file just fine but in production mode, passenger returns me the following error. No such file to load -- CSV wondering if anyone has had this issue because i thought the CSV library included in ruby 1.9.2, i am not using any gems for

Rails Engine Thread Safety - ActiveResource

ε祈祈猫儿з 提交于 2020-01-03 22:02:11
问题 My Rails 3.1 app uses an engine and I want to know if access to this engine is threadsafe. I have /lib/mymodule.rb in the engine and it looks something like this: module MyModule def self.my_method() begin data = WebResource.find(:all) # Where WebResource < ActiveResource::Base rescue data = nil end return data end end Then in my views/controllers, I call this method like this: MyModule::WebResource.headers[:some_id] = cookies[:some_id] MyModule::my_method() In my main app, I have the

How to setup a global variable in a controller

故事扮演 提交于 2020-01-03 21:48:55
问题 I take inputs from users In my index action i have: @b = Ece.find_by_code("#{params[:course]}") I want to use the value stored in @b in my show action as well as in index action. In my show action i want to do something like this: <p><%= link_to "Forum", href="/courses/#{Course.find_by_courseCode(<%= @b %>).id}", :class=>"question_button round" %> How can i setup @b to be global so that both these actions can use it Note: Ece and Course are two different models 回答1: I just wanted to use a way

Rails - WARNING: Can't mass-assign protected attributes

十年热恋 提交于 2020-01-03 21:11:57
问题 Continuing from here: Rails - Form problems, everytime I try to create a new group_membership I get this: WARNING: Can't mass-assign protected attributes: group, member at my log and the ID's are added blank. Have been making changes to the attr_accessible of my models but so far no solution. Thanks in advance. 回答1: Make sure you add :group and :member to your attr_accessible call :) 来源: https://stackoverflow.com/questions/6062971/rails-warning-cant-mass-assign-protected-attributes

Rails runner script not working

一个人想着一个人 提交于 2020-01-03 21:11:06
问题 Any ideas why this doesn't work, I get a NoMethodError when I try and run the code below via rails runner . Maybe I am calling the rails runner incorrectly, sorry new to Rails! File location: /app/scripts/data_import.rb Command: rails runner -e development DataImport.say_hi Error: undefined method `say_hi' for DataImport:Class (NoMethodError) Code: class DataImport def say_hi puts "hi" end end 回答1: You are calling an instance method on the class, so it's undefined. Try making your method a

rails 3 cookies

旧巷老猫 提交于 2020-01-03 21:04:14
问题 I have a simple app where users type in stuff in a text filed to get various results. I would like a feature where if a user enters something and then closes the browser tab, the next time they come, I can show them their previous/recent searches. This will persist even if they close the whole browser and open it again. I believe this can be done by help of cookies. Are there some good rails3 gems for using cookies or any simple tutorial that could guide me in a direction? 回答1: http:/

rails 3 cookies

泪湿孤枕 提交于 2020-01-03 21:04:11
问题 I have a simple app where users type in stuff in a text filed to get various results. I would like a feature where if a user enters something and then closes the browser tab, the next time they come, I can show them their previous/recent searches. This will persist even if they close the whole browser and open it again. I believe this can be done by help of cookies. Are there some good rails3 gems for using cookies or any simple tutorial that could guide me in a direction? 回答1: http:/

Ruby on rails, cancan and default role assignment

故事扮演 提交于 2020-01-03 20:13:32
问题 I have built a small ruby webservice, in this I have implemented cancan authorization. I followed this tutorial. The problem is that, I can't find out the way to assign at the user, when they do the registration to my site, the base role level. I find out to do this with a checkbox, but it's not what I want. My idea was to put this assignment directly into the registrations_controller, but I failed to save the role. I hope that somebody can help me. Thank you. 回答1: This is what worked for me

Testing JSON API in Rails 3.2 using rspec using exact PUT/POST bodies as Backbone would send

混江龙づ霸主 提交于 2020-01-03 19:37:35
问题 I'm trying to write a set of rspec tests for a JSON API written in Rails 3.2 with Backbone as the front end. The tests I'm writing are specifically for the Rails controllers. Now, the application itself is working fine. When a client issues a PUT request with the body: { "id":1, "name":"updated product set", ... } Everything is great. In the background Rails will take that body, then transform it into: { "id":1, "name":"updated product set", ... "model_name" => { ... } } where the hash "model

Ruby Geocoder gem to find postal code

放肆的年华 提交于 2020-01-03 18:51:47
问题 I'm using the ruby geocoder gem to search by location. I want to limit searches to locations that have officially launched. If someone searches by zip, this is easy using a regex. But if someone searches by city, I need to convert the city into a zip code, check my zip table and if positive, return the search results. The geocoder api has a section for reverse geocoding: reverse_geocoded_by :latitude, :longitude do |obj,results| if geo = results.first obj.city = geo.city obj.zipcode = geo