ruby-on-rails-3

Safari can't get HEROKU's cookie

谁都会走 提交于 2019-12-24 03:22:45
问题 I am sorry that I am not able to provide much info because I totally have no idea about this weird problem. I have a fb canvas app which is written by rails 3.2.2 . There is not any problem on my local machine (Mac OS X 10.7.4). When I deploy it to heroku, it is fine with chrome and firefox. However, when I use Safari to browse it, Safari can't get any cookie from heroku. (it shows "This site has no cookies" in developer tool, but it works well on my local machine.) I have googled this

Passing a parameter to the uploader / accessing a model's attribute from within the uploader / letting the user pick the thumbnail size

天涯浪子 提交于 2019-12-24 03:22:17
问题 I would like to crop an image to the size the user has selected from a list (e.g. 100x100px, 200x200px,...) How would I pass that attribute to the uploader or get the model's attribute from within the uploader? Accessing the model's attribute from within the uploader as following does not work: version :thumb do thumbnail_size = model.thumbnail_size ... ... end I get following error: undefined local variable or method `model' for # Thank you! Florian 回答1: In order to be able to access the

Change value of hidden_field_tag with JS (prototype & Rails 3)

僤鯓⒐⒋嵵緔 提交于 2019-12-24 03:20:31
问题 I'm riding Rails 3 and using Prototype. That said I'm only really asking a JS question.. I have a form, it's pretty simple. In the form I have a hidden field tag: <%= hidden_field_tag(:instructor_id, @instructor.id) %> That's all fine and well when I am submitting the form to one particular instructor. I have another page, however, which displays a lot of instructors. Rather than put the instructor id there myself, as in the code above, I'd like to change the value of the hidden field

Rspec don't delete 2 specific tables

十年热恋 提交于 2019-12-24 03:07:17
问题 I am using Rspec for testing a rails application. I have 2 tables I imported data into (both the test and development database) The entire application is dependent on the tables data, meaning the entire functionality is matching, calculating and measuring data from this table and putting it into other tables. so, when testing, there's no point in deleting these table's data but Rspec is still deleting the data from them. my question is: how can I force Rspec not to delete data from these

Heroku Cedar - Static Assets - Rails 3.0.x

杀马特。学长 韩版系。学妹 提交于 2019-12-24 03:04:57
问题 I've noticed that heroku injects a rails3_serve_static_assets middleware on Cedar when serve_static_assets is set to false. All I've found on this is this init script that matches the name mentioned on Heroku deploy, and all it does it re-enable the serving of static assets. I'm trying to find more information on how Heroku serves up these assets, because they don't appear to just come straight from the Rails app. When I look at the headers of a js file, for instance, they look something like

Ruby if condition not working properly in javascript file

不想你离开。 提交于 2019-12-24 02:58:36
问题 Controller: def AjaxView @vars= Var.find(:all,:conditions => { :varName=> "one" },:select=>(params[:col])) @col = params[:col] respond_to do |format| format.js { render :layout=>false } end end AjaxView.js.erb if('<%= @col %>' == 'colName'){ $("#3").text("<%= escape_javascript(render(:partial => "var")) %>"); } else if('<%= @col %>' == 'colName2'){ $("#2").text("<%= escape_javascript(render(:partial => "var1")) %>"); } View Partial: _var.html.erb <%= @vars[0].colName %> _var1.html.erb <%=

How to make this action throw a 404?

淺唱寂寞╮ 提交于 2019-12-24 02:56:27
问题 I have the following action: def show @video = @commentable = @favoritable = Video.find_by_key(params[:key]) Video.increment_counter(:views_count, @video.id) end But right now if find_by_key doesn't find a record, it throws a RuntimeError ( Called id for nil ). So how can I get that action to throw a 404 if a record isn't found? I'm running Rails 3.2.1. 回答1: Add this before you try to increment using the value of @video.id . raise ActiveRecord::RecordNotFound if @video.blank? Or use the bang

nested forms and one to one relationship

两盒软妹~` 提交于 2019-12-24 02:31:27
问题 I have a one-to-one relationship between user and goal. I want to build a form that shows the goal of a user. The problem is that my code only works when the user already has a goal defined. The text field is not rendered when no goal is present. <%= user_builder.fields_for :goal do |goal_builder| %> <%= goal_builder.text_field :goal %> <% end %> Does Rails provide an easy way to do this? 回答1: This is how I would do it : class User < ActiveRecord::Base has_one :goal accepts_nested_attributes

Rails Find_by_id raises exception

余生颓废 提交于 2019-12-24 02:25:08
问题 I was led to believe that the difference between Object.find and Object.find_by_id is that find will raise a RecordNotFound exception whereas find_by_id simply returns nil if nothing is found. However, in my Rails 3 app if I attempt to search my Uploads model with a bogus id I get: ActiveRecord::RecordNotFound in UploadsController#show Couldn't find Upload with id=59 Request Parameters: {"id"=>"59"} Here is the line of code thats messing up: @upload = Upload.find_by_id(params[:id]) I'm using

Rails vs Backbone: Who should be responsible for templates and views?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 02:22:03
问题 As an exercise, I intend to replace all front-facing aspects of my Rails application with Backbone.js. Part of the plan includes redesigning everything right down to the CSS. The issue I'm struggling with is in delegating responsibility for templates and views. Is there any benefit to implementing the new front-end entirely in Backbone, hence only using Rails as an API? How do I strike the right balance between Rails and Backbone when it comes to handling the HTML elements of the application?