ruby-on-rails-3.2

Rails routes: GET without param :id

五迷三道 提交于 2019-11-30 10:46:18
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] resources :users, :only => [:index, :update] do # I tried this match 'me', :via => :get # => api_user

Rails ActiveRecord Find / Search by Date

孤街浪徒 提交于 2019-11-30 10:10:38
I am trying to find records by 'created_at' date - the database column type is 'datetime' and I am using the UI DatePicker from jQuery my url look like this: "localhost:3000/users_supported?selected_date=2012-10-31" So far i am doing good :) and my query in controller looks like this: @support_histories = current_agent.support_histories.where(:created_at => Date.parse(params[:selected_date])) How to properly extract records by 'date' only from the 'datetime' db column I tried doing this in Rails Console, but no luck there: sh = SupportHistory.where(:created_at => DateTime.parse('2012-10-31'))

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

Deadly 提交于 2019-11-30 10:08:05
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, "Start" %> If I try the same for end_date ( <%= sort_link @q, :end_date, "End" %> ) it unfortunately

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

我的梦境 提交于 2019-11-30 08:57:50
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 In your controller action, get all images paths. @images = Dir.glob("app/assets/images/slide/*.jpg") Then

Rails 3.2.8 Application.js and Application.css are not working as expcted

Deadly 提交于 2019-11-30 08:53:19
When i try to include <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application" %> The content of the files of the application.css is: /* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the top of the * compiled file, but it's

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

我怕爱的太早我们不能终老 提交于 2019-11-30 08:39:31
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.9.2) carrierwave 0.6.2 (followed by $ bundle update ) but resizing using mini_magick returns this

Rails console default environment

吃可爱长大的小学妹 提交于 2019-11-30 08:35:18
On my development machine: $ bundle exec rails console Loading development environment (Rails 3.2.3) 1.9.3p194 :001 > Rails.env => "development" This is expected. So far, so good. Yet on my production server (to which I have deployed using Capistrano), I get exactly the same result: $ bundle exec rails console Loading development environment (Rails 3.2.3) 1.9.3p194 :001 > Rails.env => "development" On either machine, I can instead do: $ bundle exec rails console production Loading development environment (Rails 3.2.3) 1.9.3p194 :001 > Rails.env => "production" My question is: on the production

ruby bundle install require: no such files to load error

本秂侑毒 提交于 2019-11-30 08:33:00
I am running into troubles installing gems through bundle install from an app that i cloned through git. Here is the what the output from bundle install looks like: bundle install /usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8:in `require': no such file to load -- rubygems (LoadError) from /usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8 from /usr/lib/ruby/vendor_ruby/bundler.rb:11:in `require' from /usr/lib/ruby/vendor_ruby/bundler.rb:11 from /usr/bin/bundle:4:in `require' from /usr/bin/bundle:4 I read up on google and other stackoverflow questions but the file pointed to above is in

Set default value for Postgres JSON column in Rails < 4

旧时模样 提交于 2019-11-30 08:31:24
So I'm starting to use the Postgres JSON datatype, now that there's a lot of fun stuff you can do with it . In one of my Rails apps which is not yet Rails 4 (where support for Postgres JSON has been added ) I added a JSON column like this: create_table :foo do |t| t.column :bar, :json end but I can't figure out how to set a default value for the column. I tried all variations like {} , '{}' , '{}'::json , '[]'::json etc. but I either get an error when the migration runs or it simply doesn't work, meaning the migration runs but, when I create a new Foo , bar is nil . janfoeh Although a bit late

What is the difference between http_basic_authenticate_with AND authenticate_or_request_with_http_basic?

半世苍凉 提交于 2019-11-30 08:14:22
What is the difference between http_basic_authenticate_with() and authenticate_or_request_with_http_basic() methods? Thanks for your full explanation. chrisbulmer From what I can understand from the docs , http_basic_authenticate_with acts as a before filter which accepts a name and password such as http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index Whereas authenticate_or_request_with_http_basic accepts a block allowing for you to insert some code to determine whether they should be authenticated ( documentation ). E.g. before_filter :authenticate def