Rails

Rails send_file don't play mp4

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a Rails app that protects the uploaded videos putting them into a private folder. Now I need to play these videos, and when I do something like this in the controller: def show video = Video . find ( params [: id ]) send_file ( video . full_path , type : "video/mp4" , disposition : "inline" ) end And open the browser(Chrome or FF) at /videos/:id it doesn't play the video. If I put the same video at the public folder, and access it like /video.mp4 it will play. If I remove the dispositon: "inline" it will download the video

Rails 3. Creating a production database

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I create a production database in Rails 3 and load a schema to it? I tried the following approaches... I. rake db:create Rails.env='production' && rake db:schema:load Rails.env='production' II. # config/environment.rb # Set the rails environment Rails.env='production' rake db:create && rake db:schema:load ... but neither of them works. Thanks. Debian GNU/Linux 5.0.6; Rails 3.0.0; Sqlite3 3. 7 .2. 回答1: You can set the rails env off of the environment variable RAILS_ENV RAILS_ENV=production bundle exec rake db:create db:schema:load

Rails has_many :through association

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to create a rails app where user can create events and invite participants to it and need your help! I've been going in circle, trying few things but doesn't seem right at all and this is now driving me crazy!! I'm using rails 4. How would you setup the active model? User has_many : events through : meeting //for the participants? has_many : events // for the organizer? Event belongs to : user has_many : participants , class_name : "User" Participant belongs to : user has_many : events through : meeting Meeting has_many

Rails & Devise: How to authenticate specific user?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Devise for the first time with rails, and I'm having trouble with one thing: I used the provided authenticate_user! method in my user's controller to restrict access to pages like so: before_filter :authenticate_user!, :only => [:edit, :show, :update, :create, :destroy] But this allows any signed in user to access any other users :edit action, which I want to restrict to only that user. How would I do that? 回答1: In your edit method, you need to do a check to see if the user owns the record: def edit @record = Record.find(params[:id

uploading files to rails 4.0 with paperclip and simple_form

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Edit: as @Justin said, I probably messed that up when trying to find a solution without even realizing, oopsy... Changing the params to params.require(:pin).permit(:image, :description) did solve it. Though it doesn't work now because I get a "has an extension that does not match its contents. I'm following Rails One Month and trying to get upload image into a pins scaffolding working. I'm using paperclip for files, and simple_form. This is the code I think is relevant (feel free to ask for anything): _pin_form.erb.html <%= simple_form_for(

What is the Rails3 equivalent of start_form_tag?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Newbie here...I am just going through, what is clearly, an old rails tutorial. To create a form they have the following code: <%= start_form_tag(:action => 'create')%> <%= text_field(:album, :title) %><br /> <%= text_field(:album, :artist) %><br /> <%= text_field(:album, :genre) %><br /> <%= datetime_select(:album, :release_date) %><br /> <%= submit_tag("Create") %> <%= end_form_tag %> What is the proper Rails3 syntax for this code? Thanks. 回答1: Quite a lot has changed since Rails 1 and I'm really impressed by the people who are willing to

Rails 4 equivalent of Rails 3 &#039;Model.all&#039;

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In Rails 3 if I wanted to hit the db I'd take .all on the end of a query. This is useful for when I'm doing things like refreshing cache on writes (so reads always hit cache). Now in Rails 4, Model.all returns an ActiveRecord::Relation object (ie doesn't hit the db). What is the best way to get it actually go to the db and return the records specified? 回答1: Model.all.to_a in Rails 4 will give the same result as Modal.all in Rails 3. Amend: @Bigxiang, pointed out in his comment to try Model.all.load , this method for certain hits the database

A/B framework for Rails 3?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there anything like ABingo or Vanity that works in Rails 3? I know there's Google Website Optimizer, and Visual Website optimizer, but I need more power w/ regard to determining what is displayed, and what is in turn tracked than they can provide. If not, I'll even take thoughts on frameworks that are relatively simple enough that I might be able to convert them to Rails 3 compliance easily. 回答1: Andy Atkinson has written Rails 3 Getting Started guides for A/Bingo and Vanity . 文章来源: A/B framework for Rails 3?

Ruby on Rails: how do I sort with two columns using ActiveRecord?

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to sort by two columns, one is a DateTime ( updated_at ), and the other is a Decimal (Price) I would like to be able to sort first by updated_at, then, if multiple items occur on the same day, sort by Price. 回答1: Assuming you're using MySQL, Model.all(:order => 'DATE(updated_at), price') Note the distinction from the other answers. The updated_at column will be a full timestamp, so if you want to sort based on the day it was updated, you need to use a function to get just the date part from the timestamp. In MySQL, that is DATE() .

Rails: JS Controller Being Called Twice for Some Reason

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: For some reason when I click on a button, my controller and the resulting jquery function gets called twice. Since the js function being called is toggle, this is a problem as it causes the code to jump in and out of view. Here is the form: Unseen Notifications: <%= current_user.notification_unseen %> </div> <%= button_to "show", {:action => "seen", :controller=>"notifications"}, :remote => true %> Here is the controller: def seen respond_to do |format| format.js end end Here is the jquery: $("div#notifications").toggle(); $("div#count")