ruby-on-rails-3

Rails 3 DRY Conditional Layout for iframes

自古美人都是妖i 提交于 2019-12-23 05:20:57
问题 I was recently tasked with loading a portion of my Rails application within an iframe on another website. The relevant pages should be using a different layout file, but only if they're being rendered inside of the iframe. There was a solution proposed here Detect iframe request in a rails app that involved passing a query string parameter. For example the requesting website could call my application through an iframe with the src of http://foo.com/bar?iframe=true . Then in our controller we

Rails gem api method chaining dynamic

泪湿孤枕 提交于 2019-12-23 05:20:06
问题 I am a fan of Grackle and Gibbon as they make api queries very simple. I like for example that with grackle, you can chain the methods which will interpolate to the url request. For example: client.users.show? :screen_name=>'some_user' #http://twitter.com/users/show.json?screen_name=some_user Notice the .users and .show results to /users/show How can I write code to do so? Such that I can have Some_class.method1.method2 回答1: Method chaining usually works by implementing instance methods that

Rails3 routing precedence

我的未来我决定 提交于 2019-12-23 05:19:49
问题 I'm creating a simple CMS with Rails 3. In my routes.rb file I have the following entry to catch all routes: match '*url', :controller => 'site', :action => 'dynamic_page' I'm using ckeditor gem for editor support. My rake routes is as follows: root /(.:format) {:action=>"index", :controller=>"site"} /*url(.:format) {:action=>"dynamic_page", :controller=>"site"} ckeditor_pictures GET /ckeditor/pictures(.:format) {:action=>"index", :controller=>"ckeditor/pictures"} ckeditor_pictures POST

Getting warning : Denial of Service

倖福魔咒の 提交于 2019-12-23 05:17:36
问题 Customer.find(:all, :select => 'id', :order => 'updated_at DESC', :readonly => true, :conditions => { :status_id => Customer.id_for_status(params[:id].to_sym) }, :offset => offset, :limit => 30).collect(&:id) Above is my query in that I am getting warning like Symbol conversion from unsafe string (parameter value) near line 33: params[:id].to_sym This is the warning of Denial of Service. Anybody have any idea how can I fix this warning? Thanks In Advance 回答1: The problem here is params[:id]

AJAX request hits server from every page and I can't find the source of that original AJAX call

杀马特。学长 韩版系。学妹 提交于 2019-12-23 05:16:13
问题 Somewhere in my thousands of lines of javascript, an ajax call is being made. I cannot for the life of me figure out where it is coming from. It seems to happen right after a page loads. I can see in firebug that the ajax call is being made. The ajax call always requests the current page. So, for example, once users#new loads, it asks for users#new.js and also does the same with every other controller and action. Is there a way I can determine where in the code it is being called from? 回答1:

How to use post method for fetching data from client in def create function of ROR

允我心安 提交于 2019-12-23 05:14:55
问题 I am struggling with these question,how to fetch data from client side,how to use post method in def create function,to fetch the data from client side. Client side coding is android,Server side code is ROR. server side coding in ror def create respond_to do |format| @post = Post.new(params[:post]) if @post.save flash[:notice] = "Prayer Successfully created." @posts = Post.paginate(page: params[:page],:per_page => 5) format.json{ render :json => @post, :status => :created } else flash[:notice

Is that possible to use paginate with Acts_as_follower?

匆匆过客 提交于 2019-12-23 05:13:32
问题 @users = User.find_by_username(params[:username]).all_following.order("created_at DESC").paginate(page: params[:page]) This calculation won't work:( I'd like to use pagination and order sort with acts_as_follower. 回答1: You can pass the order (and any other option ActiveRecord#all accepts) directly to all_following like this @users = User.find_by_username(params[:username]).all_following(:order => 'created_at DESC').paginate(page: params[:page]) UPDATE : will_paginate can paginate an array but

NoMethodError within nested model form

故事扮演 提交于 2019-12-23 05:12:19
问题 The project is a simple workout creator where you can add exercises to a workout plan. I've been following the Railscast covering nested model forms to allow dynamically adding and deleting exercises, but have run into an error and need a second opinion as a new developer. The error I am continually receiving is: NoMethodError in Plans#show This is the extracted code, with starred line the highlighted error: <fieldset> **<%= link_to_add_fields "Add Exercise", f, :exercise %>** <%= f.text

Rails - Attaching image through paperclip on nested fields causes unwanted/unavoidable redirect_to

谁说胖子不能爱 提交于 2019-12-23 05:12:04
问题 I have a form in my project for a model Artworks where I am using fields_for for a resource Photo where Artworks has_many :photos . The Photo model uses paperclip to attach images. All my forms are AJAX based, meaning the page should never be reloaded, and I shouldn't be using redirect_to anywhere in my controllers (and I'm not). When I include the fields_for in my form with the paperclip file_field, if I create or update the photo when I submit the form, I get the following error: Template

Rspec2 partial view gives nil:NilClass. Why?

爱⌒轻易说出口 提交于 2019-12-23 05:11:20
问题 I am trying to get going with development of view components with Rspec2 and Rails3. However, I make the following observation, and I don't understand what is going on, and how to fix this. In my spec I define: describe "main/index.html.erb" do it "displays a photo url in products partial" do assign(:designs, [stub_model(Design, :name => "test", :photo => "photo_url")]) render rendered.should contain("photo_url") end end When I run: rspec spec/view/main_spec.rb I get this error: 1) main/index