ruby-on-rails-3.2

Adding a staging environment to the workflow [closed]

有些话、适合烂在心里 提交于 2019-11-29 22:24:31
I currently have two environments in which I work: development locally and production on Heroku. I would like to add a staging environment on Heroku to see that everything goes as expected before pushing the app live to users. Preferably, the staging environment should have the exact same settings and data as the production environment. What are the steps needed to accomplish the above? berislavbabic First the predispositions, i like to have my heroku git remotes set up as staging and production so you can easily use git push staging/production to deploy to each one of them. I'll be using that

Nested attributes for belongs_to association rails

蓝咒 提交于 2019-11-29 17:44:39
问题 I have two models, Complaint and Company. Complaint belongs_to and accepts_nested_attributes for Company, and Company has_many Complaints. # Models class Complaint < ActiveRecord::Base attr_accessible :complaint, :date, :resolved belongs_to :user, :class_name => 'User', :foreign_key => 'id' belongs_to :company, :class_name => 'Company', :foreign_key => 'id' has_many :replies accepts_nested_attributes_for :company end class Company < ActiveRecord::Base attr_accessible :name has_many

Too Few Arguments

蹲街弑〆低调 提交于 2019-11-29 15:57:40
问题 I am trying to get some Javascript working in my Rails app. I want to have my index page allow me to edit individual items on the index page, and then reload the index page upon edit. My index.html.erb page looks like: <div id="index"> <%= render 'index' %> </div> In my index.js.erb I have: $('#index').html("<%=j render 'index' %>"); and in my holders_controller: def edit holder = Holder.find(params[:id]) end def update @holder = Holder.find(params[:id]) if @holder.update_attributes(params[

Rails routes: GET without param :id

和自甴很熟 提交于 2019-11-29 15:55:20
问题 I'm developing a REST api based on rails. To use this api, you MUST be logged in. Regarding that, I'd like to create a method me in my user controller that will return a json of the logged in user infos. So, I don't need an :id to be passed in the URL. I just want to call http://domain.com/api/users/me So I tried this: namespace :api, defaults: { format: 'json' } do scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do resources :tokens, :only => [:create, :destroy]

Rails check_box_tag how to pass value when checked ajaxily

南楼画角 提交于 2019-11-29 15:43:44
问题 On my index page for my Task model, I want to show a checkbox for every row that corresponds to the boolean field "complete" in my Task database table. Currently my code gets into the method "Complete", but it does not contain the value of the checkbox that the user just did (i.e. if they just checked the box, it does not pass true to my "Complete" method). How can i pass the value that the user just performed - either checked or un checked? /views/tasks/index.html.erb <% @tasks.each_with

Rails & Ransack - Sorting/searching based on a definition in the model

落花浮王杯 提交于 2019-11-29 14:49:34
问题 Say for example I have an event with start_date and length (as integer representing days). In the model I define end_date as start_date + length.days very simply as you would expect: def end_date start_date + length.days end All works fine in the template, I can use event.end_date to display the start date plus however many days length was set to, however , I want to now order the events by the end date using Ransack. The sort link for start_date looks like this: <%= sort_link @q, :start_date

Ruby on Rails: Custom Devise Registration Controller, Asking For Create Action

拜拜、爱过 提交于 2019-11-29 14:11:41
问题 I have a custom registration controller, but I don't want to override a create action from devise. When I try to sign up a user, I get this error: Unknown action The action 'create' could not be found for Devise::RegistrationsController Is it asking for it because I have a custom registration controller? If so, does that mean I need to copy all the actions that I'm not overriding from here: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb

Rails How To List all Images in a Folder using the image_tag?

三世轮回 提交于 2019-11-29 13:04:31
问题 Im trying to take all the images in the 'app/assets/images/slide' folder and put them withing tags (in order). So, it will look like this : <img src="1.jpg" > <img src="2.jpg" > <img src="3.jpg" > How can I achive this? (Im using Rails 3.2.9) Here's the code I tried (thanks to Khaled). But it outputs a plain text list of all image paths. I need the images to show : @images = Dir.glob("app/assets/images/slide/*.jpg") @images.each do |image| image_tag image.gsub("app/assets/images/", "") end

Rails/ActiveRecord sort by particular value

一笑奈何 提交于 2019-11-29 12:47:57
Is there any convenient way in Rails 3.2 to order an ActiveRecord relation by moving records with a particular value for a particular field to the front of the relation? For instance, if MyModel has an attribute country , I would like to sort relations returned by any query with records having country='Spain' to the front of the relation. Something like this. Obviously 'name, id' would depend on your model and requirements. MyModel.order("country = 'Spain' DESC, name, id") 来源: https://stackoverflow.com/questions/17073194/rails-activerecord-sort-by-particular-value

Carrierwave Error Msg: Failed to manipulate with MiniMagick, maybe it is not an image?

笑着哭i 提交于 2019-11-29 12:19:11
问题 I am upgrading my app to Rails 3.2 on Ruby 1.9. I had to drop attachment_fu . Carrierwave seemed the obvious replacement. At this stage I am uploading files to the file system (no cloud files, yet). I am on Lion, XCode 4.3.2, Command Line Tools installed. Running: $ brew doctor # Your system is raring to brew. I can upload and resize images in this configuration: rails 3.1.4 ruby 1.8.7 carrierwave 0.5.8 mini_magick 3.4 I can upload images in the new configuration: rails 3.2.3 ruby 1.9.3 (or 1