ruby-on-rails-3

Active record has_many association for one model having two types of values

泪湿孤枕 提交于 2020-01-15 08:16:28
问题 i am facing a new situation. I know someone definitely had faced these type of situation: I have an invoices table and an invoice_line_items table. Till now every thing is going well with has_many and belongs to association. Now i want to add tax accounts in invoice items, for that i don't want to create a separate table, hence i make below changes in my invoice model : invoice.rb: class Invoice < ActiveRecord::Base has_many :invoice_line_items has_many :tax_line_items, :class_name =>

Undefined method

拜拜、爱过 提交于 2020-01-15 07:38:19
问题 Below is my index.html.erb (I just want to show a list of Brands and associated Subbrands) <h1>Brands</h1> <% @brands.each do |brand| %> <h2><%= brand.name %></h2> <% end %> <% @brands.subbrands.each do |subbrand| %> <h2><%= subbrand.name %></h2> <% end %> The error I receive when viewing index.html is: undefined method `subbrands' for #<Array:0x9e408b4> Here is my brands_controller: class BrandsController < ApplicationController def index @brands = Brand.all respond_to do |format| format

Ransack search, how to search for each word by splitting input search parameter

偶尔善良 提交于 2020-01-15 07:11:48
问题 I am currently experimenting using the ransack gem to conduct a search on a model in Rails. As it stands I am using the basic setup. Controller: def index @q = Person.search(params[:q]) @people = @q.result(:distinct => true) end View: <%= search_form_for @q do |f| %> <%= f.label :name_cont %> <%= f.text_field :name_cont %> <%= f.submit %> <% end %> I have managed to find lot of information about conducting searches on multiple fields, however, I haven't managed to find anything to help me to

time_select blank field saves a default time when form is submitted

痞子三分冷 提交于 2020-01-15 06:41:47
问题 Im having trouble understanding my options for time_select. My goal is to have only user created time selections render in my show action after form submission. What is happening however is a default time of 12:00 AM being rendered for all time_select fields not touched by a user. I am looking for a way to either stop default time values from saving (which if I had to guess, isn't possible), or create a conditional that would allow me to prevent default time values from rendering. I have

How to restrict Sunspot search with nested models?

孤者浪人 提交于 2020-01-15 06:35:10
问题 I want to filter the Sunspot search results with with(:is_available, true) . This is working with the User model, but I can't make it work with the Itinerary model. app/controllers/search_controller.rb: class SearchController < ApplicationController before_filter :fulltext_actions private def fulltext_actions @itineraries = do_fulltext_search(Itinerary) @users = do_fulltext_search(User) @itineraries_size = @itineraries.size @users_size = @users.size end def do_fulltext_search(model) Sunspot

How to restrict Sunspot search with nested models?

独自空忆成欢 提交于 2020-01-15 06:34:29
问题 I want to filter the Sunspot search results with with(:is_available, true) . This is working with the User model, but I can't make it work with the Itinerary model. app/controllers/search_controller.rb: class SearchController < ApplicationController before_filter :fulltext_actions private def fulltext_actions @itineraries = do_fulltext_search(Itinerary) @users = do_fulltext_search(User) @itineraries_size = @itineraries.size @users_size = @users.size end def do_fulltext_search(model) Sunspot

How do I deal with ajax based sub components in rails 3?

﹥>﹥吖頭↗ 提交于 2020-01-15 06:30:28
问题 I'm refactoring a rails 3 application, and want to know how best to deal with ajax based sub components? I have a 'dashboard' controller. Which is rendered via the 'dashboard#show' action. And I now want to have an ajax based 'tabs' component, which is part of the dashboard. I have two possible solutions: solution 1: implement the tabs component as an action e.g. 'dashboard#tabs' (this is my current solution). This gives me ugly helpers: tabs_dashboard_path solution 2: implented it as nested

Showing spinner for Rails 3 UJS gets Type error

☆樱花仙子☆ 提交于 2020-01-15 06:13:29
问题 I have three links in my Rails 3 app that load information in the container beneath them using UJS. To complete the experience I want to display a bit of 'Loading...' text while the information loads. So I used some jQuery from Simone Carletti's post to try to accomplish it. Depending on the jQuery, though, two different things happen when the first link is clicked. (In both scenarios, nothing happens when the other two are clicked.) Given the code below I get TypeError: 'undefined' is not a

meta tag parsing in Rails [closed]

自作多情 提交于 2020-01-15 05:47:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I was looking for something to help me parse general meta-tags from websites similar to this github project I found for open graph data. Here's a demo app. Basically, I'd like to be able to have a user input a URL from a news site and have it retrieve from that the Title, Desc, etc., leaving as little work

undefined method `valid_options' for nil:NilClass with simple_form and Mongoid

自古美人都是妖i 提交于 2020-01-15 05:40:27
问题 I have two models, Category and Post. Category.rb class Category include Mongoid::Document field :title, :type => String has_many :posts, :autosave => true, dependent: :destroy end Post.rb class Post include Mongoid::Document field :title, :type => String belongs_to :category end I'm using simple_form gem If I write in my post form the next: <%= simple_form_for(@post) do |f| %> <%= f.collection_select :category, Category.all, :id, :title, :prompt => "Choose a Category"%> <%= f.input :title %>