ruby-on-rails-3.1

calling javascript functions from html in rails 3.1

淺唱寂寞╮ 提交于 2019-12-11 02:24:11
问题 Using coffeescript, jQuery, and sprockets in rails 3.1 the coffeescript files are compiled in to blocks like: (function() { var a; var b; var c; foo = function() { alert("foo"); } bar = function() { alert("bar"); } }).call(this); This seems to move functions foo and bar out of global scope, so bar can be called by foo, but neither can be called from the html code. When I try to call foo from a select onchange element, I get a "Can't find variable: foo". The workaround right now is to move all

How to filter results with Ransack

不问归期 提交于 2019-12-11 02:03:40
问题 I am trying to implement Ransack for a search feature on my website. I tried watching the Railscasts on Ransack and got a pretty good idea of how to implement it. But I am running into an issue that I can't seem to figure out. In the Index action of my Users controller, I have the following code: def index @users = User.same_city_as(current_user) end @users is an ActiveRecord::Relation object. @users is essentially capturing all the users who belong to the same city as the current_user . In

Rails 3.1 Different Views for One Model

╄→гoц情女王★ 提交于 2019-12-11 01:55:55
问题 I have an application where I have a Shipment model. I have created a view that allows me to create shipments and view shipments in a table based layout. Everything lies in the index.html.erb because all actions are done through ajax. When a shipment is created, the status is "OPEN" by default. Later on when a bill of lading is printed, the status will change to "PRINTED". My goal is to create another view that lists only the open shipments allowing an operator to print the bill of lading

rails sending the wrong content-type in ajax response

我们两清 提交于 2019-12-11 00:59:51
问题 I have been struggling terribly for the better part of the day with the following problem: I have a rails 3.1 app - running fine I am trying to add some ajax to it However, no matter what I try, Rails insists on sending the wrong content-type in the response header. #the form = form_for @signup, :url => '/signup', :remote => true do |f| = f.text_field :email, :class => 'email', :size => 26 = f.submit 'Notify me' #In the controller def create respond_to do |format| format.js { render :content

correct way to find max value with association rails

删除回忆录丶 提交于 2019-12-11 00:58:35
问题 I have the following models: #equipment.rb class Equipment < ActiveRecord::Base belongs_to :odometer_type has_many :odometers end #odometer.rb class Odometer < ActiveRecord::Base belongs_to :equipment # I am currently doing this to find the last mileage entered (which is wrong too cause I want the mileage from the max date entered) def self.current_reading(equipment) all.where(:equipment_id => equipment.id).max(:mileage) end end This looks even worse in the view, like this: = @equipment

rails carrierwave backgrounder with delayed jobs taking too much time to upload

喜欢而已 提交于 2019-12-10 22:18:19
问题 I am using carrierwave and carrierwave backgrounder(https://github.com/lardawge/carrierwave_backgrounder) with delayed job for uploading file in a background.whernver i try to upload my file, it uploads successfully and i can see that jobs are executed in the background , but i cant see any difference with using delayed job and without using delayed job.it takes same time to execute without delayed job as it takes with delayed job.dont know what went wrong plz help.Thanks in advance. here is

HTML <form> tag causing Rails form to submit a GET instead of POST request

烂漫一生 提交于 2019-12-10 21:21:42
问题 I have a form that works fine until I add the tags for styling (I am using twitter bootstrap). The app is Rails 3.1 and I am on a mac. Here is a form that works fine with no issues: <%= form_for @user do |f| %> <% if @user.errors.any? %> <div class="alert-message error"> <h2>Form is invalid</h2> <ul> <% for message in @user.errors.full_messages %> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :email %> <%= f.text_field :email %> </div> <div class=

file.png isn't precompiled

…衆ロ難τιáo~ 提交于 2019-12-10 20:27:19
问题 I thought I had the assets pipeline figured out, but not any more. I have a stylesheet named clients.css.scss .client { .list_view { width: 650px; height: 500px; overflow: auto; table { width: 650px; border: solid 2px #999999; border-collapse: collapse; thead tr { background: image-url('list-view-header.png') repeat-x; } thead tr:first-child { background-image: none; } } } } Every time I try to precompile it in production I keep getting a "file.png isn't precompiled" error. bundle exec rake

Rails 3.1 app with integrated webdav and authentication?

廉价感情. 提交于 2019-12-10 19:36:29
问题 I would like to enable WebDav for Rails 3.1 application, where I use Devise for authentication and CanCan for authorization. So far I turned on WebDav and works fine. Is it possible to use Devise logins/users with dav4rack to enable/restrict access to certain files/directories on WebDav? Maybe there is already a howto or wiki page about that? Any help will be appreciated. PS. is this the right way of solving this kind of problem? maybe i should switch back to apache mod_dav and synchronise

Rails 3.1 multiple objects on one form

梦想与她 提交于 2019-12-10 19:08:44
问题 I've checked out a lot of questions for putting multiple objects on one form, but they seem to be out of date. I have a bunch of user objects: def index @users = User.all @user = current_user end that I need to edit in a form. They all have roles which will be edited on the form. The form is rendered in a partial, and nothing shows up, just 'admin form' plaintext. users/_admin.html.erb admin form <% form_for "user[]", :url => users_path do |f| %> <ul> <li class="layout"> <div class="header">