ruby-on-rails-3.2

Rails controller create action difference between Model.new and Model.create

早过忘川 提交于 2020-01-01 02:43:25
问题 I'm going through a few Rails 3 and 4 tutorial and come across something I would love some insights on: What is the difference between the Model.new and Model.create in regards to the Create action. I thought you do use the create method in the controller for saving eg. @post = Post.create(params[:post]) but it looks like I'm mistaken. Any insight is much appreciated. Create action using Post.new def new @post = Post.new end def create @post = Post.new(post_params) @post.save redirect_to post

Bundle install failed due to unf_ext (0.0.5) gem

 ̄綄美尐妖づ 提交于 2020-01-01 02:39:07
问题 I have installed ruby 1.9.3p327 & rails 3.2.8 using rvm on centos 6.3. But while doing bundle install for a particular project folder, the process fails in between when it tries to install gem unf_ext 0.0.5 and throws following error, Installing unf_ext (0.0.5) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /home/rradmin/.rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb -fPIC checking for main() in -lstdc++... yes checking for ruby

Rails 3.2, RSpec, Factory Girl : NameError: uninitialized constant Factory

社会主义新天地 提交于 2019-12-31 10:59:05
问题 Ive been following this introductory to Rails testing and Ive run into an issue I cant seem to find the solution to. Im very familiar with Rails but this is my first foray into testing. Anyhow, I have a very basic model test, not even fully implemented and when I try and run rspec spec/models/admin_spec.rb . I get the following error in the Admin has a valid factory line (full code below) Admin has a valid factory Failure/Error: Factory.create(:admin).should be_valid NameError: uninitialized

How to put a login form in the header for Devise and Rails

烈酒焚心 提交于 2019-12-30 10:39:50
问题 I want to put a login form in the header of my website. I use Rails 3.2.8 and the latest Devise. In the app/views/devise/sessions/new.html.erb file a login form is created with: <%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:class => 'main'}) do |f| %> <div><%= f.label :login %> <%= f.text_field :login, :placeholder => 'Enter username' %></div> <div><%= f.label :password %> <%= f.password_field :password, :placeholder => 'Enter password' %></div>

How to put a login form in the header for Devise and Rails

╄→гoц情女王★ 提交于 2019-12-30 10:39:28
问题 I want to put a login form in the header of my website. I use Rails 3.2.8 and the latest Devise. In the app/views/devise/sessions/new.html.erb file a login form is created with: <%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:class => 'main'}) do |f| %> <div><%= f.label :login %> <%= f.text_field :login, :placeholder => 'Enter username' %></div> <div><%= f.label :password %> <%= f.password_field :password, :placeholder => 'Enter password' %></div>

Ajax queue Backbone js

痞子三分冷 提交于 2019-12-30 08:10:05
问题 I am running Backbone js 0.9.2 on Rails 3.2.2,I have a page for adding cost rows.A cost have 3 TextFields: title, description and price. I am saving each cost on blur. model.save() gets called multiple times with very short intervals. Which issues one create(post) request then one update(put) request shortly there after. The problem I am experiencing is that PUT request sometimes reaches the server before the POST, the result being that model gets created and persisted twice(duplicates). To

How to do an Ajax GET request to get data from rails and pass it to javascript(google maps)?

不问归期 提交于 2019-12-30 07:18:11
问题 I have a model Locations with two columns latitude and longitude. I want to find a way where I can get the list of locations and pass them to google maps using Ajax and javascript. So far my code is as follows: map.js: function initialize() { var map; var latlng = new google.maps.LatLng(37.09, -95.71); var options = { zoom: 5, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: true, disableDoubleClickZoom: true, noClear: true, navigationControl: true,

Rails ActiveRecord Find / Search by Date

社会主义新天地 提交于 2019-12-30 03:24:47
问题 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

Uploading a remote file url from Rails Console with Carrierwave

℡╲_俬逩灬. 提交于 2019-12-30 00:13:08
问题 I just wanted to know how one would go about uploading a remote file url using Carrierwave in the Rails console. I tried the following without any luck. I presume it's not processing the Uploader? user = User.first user.remote_avatar_url = "http://www.image.com/file.jpg" user.save Many thanks 回答1: Take a look at the ' Uploading files from a remote location ' section on this page https://github.com/carrierwaveuploader/carrierwave CarrierWave should throw an error if the url of the location is

Adding a staging environment to the workflow [closed]

余生颓废 提交于 2019-12-29 14:15:50
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . 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