ruby-on-rails-3

Ruby on Rails Callback, what is difference between :before_save and :before_create?

倖福魔咒の 提交于 2019-12-28 03:15:11
问题 Could you explain in detail what the :before_save and :before_create Ruby on Rails callbacks are, and what they have to do with Rails validations? Does validation occur after :before_save or :before_create ? 回答1: In a create operation under Rails, there are six callbacks before the database operation, and two after. In order, these are: before_validation before_validation_on_create after_validation after_validation_on_create before_save before_create DATABASE INSERT after_create after_save

Can we call a Controller's method from a view (as we call from helper ideally)?

我的未来我决定 提交于 2019-12-28 02:39:26
问题 In Rails MVC, can you call a controller's method from a view (as a method could be called call from a helper)? If yes, how? 回答1: Here is the answer: class MyController < ApplicationController def my_method # Lots of stuff end helper_method :my_method end Then, in your view, you can reference it in ERB exactly how you expect with <% or <%= : <% my_method %> 回答2: You possibly want to declare your method as a "helper_method", or alternatively move it to a helper. What do helper and helper_method

Changing the base URL for Rails 3 development

若如初见. 提交于 2019-12-28 02:39:14
问题 I know I'm going to deploy to an environment with my application running with a base URL which looks like this: http://someserver/mydepartment/myapp My development environment is set up to use the default Rails configuration, which looks like this: http://localhost:3000/myapp I'd like to model this deployment path in my development environment. That is, I'd like to develop with a base URL which looks like this: http://localhost:3000/mydepartment/myapp That way, I can make all my URLs relative

Using a Rails helper method within a javascript asset

吃可爱长大的小学妹 提交于 2019-12-27 16:39:13
问题 Is there any way to use a Rails helper method, more specifically, a path helper method within a javascript asset file. This file foo.js.coffee.erb $('#bar').val("<%= create_post_path %>") I would love it if I could get from erubis $('#bar').val("path/to/create") 回答1: You can include any helper/module/class in an erb template with: <% environment.context_class.instance_eval { include MyHelper } %> See: https://github.com/rails/sprockets/blob/master/lib/sprockets/environment.rb and https:/

Path helpers generate paths with dots instead of slashes

只谈情不闲聊 提交于 2019-12-27 13:35:48
问题 In my routes.rb I have the following: resources :message_threads When I call: message_threads_path(1) I get: /message_threads.1 Why is this? My other resources work fine. Am I not pluralizing this correctly or something? 回答1: Yes, this is a pluralization error. By passing the ID 1, I assume that you wish to display a single record. So you need to use the singular 'message_thread': message_thread_path(1) Which will yield: http://localhost:3000/message_threads/1 回答2: Sometimes this also is when

Path helpers generate paths with dots instead of slashes

為{幸葍}努か 提交于 2019-12-27 13:35:26
问题 In my routes.rb I have the following: resources :message_threads When I call: message_threads_path(1) I get: /message_threads.1 Why is this? My other resources work fine. Am I not pluralizing this correctly or something? 回答1: Yes, this is a pluralization error. By passing the ID 1, I assume that you wish to display a single record. So you need to use the singular 'message_thread': message_thread_path(1) Which will yield: http://localhost:3000/message_threads/1 回答2: Sometimes this also is when

Rails routing to handle multiple domains on single application

不羁的心 提交于 2019-12-27 12:10:45
问题 I've been unable to find a workable solution to this problem, despite several similar questions here and elsewhere. It seems likely that this question hasn't been answered for Rails 3, so here goes: I have an application that currently allows users to create their own subdomain that contains their instance of the application. While in Rails 2 you were best served using the subdomain-fu gem, in version 3 it's dramatically simpler, as per the Railscast -- http://railscasts.com/episodes/221

Ruby on rails server crashing when adding a new account for open source project Kandan

♀尐吖头ヾ 提交于 2019-12-27 04:25:45
问题 I can successfully get my local server running with open source project kandan using ruby on rails, however as soon as I click the "create new account" button, it redirects me to the home page as expected but then the server crashes immediately. This is the error I am getting on the server: It would be great if someone could help me out! EDIT Here is the routes file Kandan::Application.routes.draw do devise_for :users, :controllers => { :sessions => "sessions" } devise_scope :user do

Ruby on rails server crashing when adding a new account for open source project Kandan

大憨熊 提交于 2019-12-27 04:22:04
问题 I can successfully get my local server running with open source project kandan using ruby on rails, however as soon as I click the "create new account" button, it redirects me to the home page as expected but then the server crashes immediately. This is the error I am getting on the server: It would be great if someone could help me out! EDIT Here is the routes file Kandan::Application.routes.draw do devise_for :users, :controllers => { :sessions => "sessions" } devise_scope :user do

API formation for side loading only required associated data to ember data

扶醉桌前 提交于 2019-12-26 00:49:17
问题 Please check my previous question EMBER JS - Fetch associated model data from back-end only when required Related to the above question I need help on API formation in ruby on rails(JSON format: jsonapi.org) how to form the API for sideloading only students.records and link with data already available in ember-data store (school and students) 回答1: based on the comments in the other question, I think you're wanting something like GET /api/students?include=records But you need that filtered to