ruby-on-rails-3

render partial of another namespace

隐身守侯 提交于 2020-01-06 03:49:27
问题 I have a problem. I need to render objects using partials of another namespace. render complain.target it tryes to render partial from current namespace(current is admin ) Missing partial admin/bulletins/bulletin... I dont need to render it from admin/.. I cant specify partial path like render partial: '/bulletins/bulletin', locals: { bulletin: complain.target } But it's polymorphic association, and different partial pathes are used. Is it any way to do it? Thanks in advance! 回答1: There seems

Path defined in controller and action is getting ignored, Ruby on Rails

落爺英雄遲暮 提交于 2020-01-06 03:44:05
问题 According to http://guides.rubyonrails.org/layouts_and_rendering.html I should be able to define the path from a different controller as I have done in my create action in my micropostscontroller: def create @micropost = current_user.microposts.build(params[:micropost]) if @micropost.save flash[:success] = "Micropost created!" redirect_to profile_path else render 'static_pages/profile' end end When I unsuccessfully create a post, however (leave it blank or make it too long), the page '

I get a “Pending Error” whenever I click on Pay using Payola-Payment Gem (A gem made for Stripe) in my Rails 4.2.1 application

有些话、适合烂在心里 提交于 2020-01-06 03:10:08
问题 Using Payola-Payments Gem to handle Stripe Payments, it's necessary to set Background Worker for your transaction. After setting up Background Worker using ActiveJob, I will get error when I click pay. Here is it : Note: Am using Windows Environment (Windows 8) and I believe there is something am doing wrong here. Error Alert Renders on my View: This seems to be taking too long. Please contact support and give them transaction ID: ook4dp Here is the generated code from Console Started POST "

what is recommended for handling password for new Facebook signed in users?

别来无恙 提交于 2020-01-06 02:59:07
问题 When let users sign in using Facebook, I create a new devise user after first authentication, the question is what is the better practice to do regarding the password of newly created user ? 1. Fill it with a random token? Then, how would the user know the newly created password ? a. Shall I send him an email? b. Write it as a flash message after his first Facebook authentication ? I know that user might not need to have a password as he can always sign in with Facebook, but, he might need to

CScript Error: Execution of the Windows Script Host failed - Rails rake assets:precompile

[亡魂溺海] 提交于 2020-01-06 02:44:30
问题 I am deploying rails project on heroku. When I use rake assets:precompile it gives following error - rake aborted! CScript Error: Execution of the Windows Script Host failed. (0x800A0007) (in c:/Rails Projects/sheets_vip_rails/app/assets/javascripts/application.js) Tasks: TOP => assets:precompile:primary (See full trace by running task with --trace) rake aborted! Command failed with status (1): [c:/Ruby193/bin/ruby.exe c:/Ruby193/bin/rak...] Tasks: TOP => assets:precompile (See full trace by

Appending text onto current URL through link in rails

喜夏-厌秋 提交于 2020-01-06 02:42:27
问题 Lets say the current page a user is on is: http://0.0.0.0:3000/posts?direction=asc&sort=title Its sorted ascending, by title. Now lets say I have a search engine, that if you searched for "chicken" for example, the url might be: http://0.0.0.0:3000/posts?direction=asc&search=chicken&sort=title But instead of searching, I'd like to make a link such as <a href="CODE HERE">Show all results for chicken</a> which appends &search=chicken to url, or if search already has a value, replaces it. Is

Rails: Search in has_one association

北城以北 提交于 2020-01-06 02:38:06
问题 I have a model called User which has_one Player . A Player belongs_to a User . I want to find all the Players which Users attributes City has a particular value. Right now I have this in my Player model: def find User.find(:all, :conditions => ['city LIKE ?', "%#{city}%"]) end However that gives me the User. I want the Players which Users satisfy that condition. How do I do that? 回答1: Try this. Player.joins(:user).where('user.city LIKE ?', "%#{city}%") 来源: https://stackoverflow.com/questions

ActiveRecord find categories which contain at least one item

扶醉桌前 提交于 2020-01-06 02:36:05
问题 Support I have two models for items and categories, in a many-to-many relation class Item < ActiveRecord::Base has_and_belongs_to_many :categories class Category < ActiveRecord::Base has_and_belongs_to_many :items Now I want to filter out categories which contain at least one items, what will be the best way to do this? 回答1: please notice, what the other guys answererd is NOT performant! the most performant solution: better to work with a counter_cache and save the items_count in the model!

Rails template conditions

时间秒杀一切 提交于 2020-01-06 02:11:28
问题 In PHP I did template consitions with such code: <?php if($item['taste'] > 0):?>taste_plus<?php elseif($item['taste'] == 0):?>taste_zero<?php else:?>taste_minus<?php endif;?> And I did number formatting with <?php echo number_format($item['taste'], 2)?> for fetch them to "2.00" format. How to do things like that in Rails templates? 回答1: A direct translation of your template code would look something like this: <% if @item.taste > 0 %>taste_plus<% elsif @item.taste == 0 %>taste_zero<% else %

Polymorphic Comments with Ancestry Problems

烈酒焚心 提交于 2020-01-06 01:59:25
问题 I am trying to roll together two Railscasts: http://railscasts.com/episodes/262-trees-with-ancestry and http://railscasts.com/episodes/154-polymorphic-association on my app. My Models: class Location < ActiveRecord::Base has_many :comments, :as => :commentable, :dependent => :destroy end class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end My Controllers: class LocationsController < ApplicationController def show @location = Location.find(params[:id]) @comments