This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
keys = [] | |
CSV.foreach("/path/to/stuff/to/import.csv") do |row| | |
keys = row and first = false if first | |
ModelName.create(Hash[*keys.each{|k| k.strip!}.zip(row.each{|k| k.strip!}).flatten]) unless first | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "Question", :search => true do | |
before(:each) do | |
@buyer = Buyer.first | |
@item = RareBook.first | |
host! 'mmplus.dev' | |
Capybara.app_host = "http://mmplus.dev" | |
reset_email |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper.rb' | |
describe "Phone call", :search => true do | |
it "should be created without user logged in" do | |
email_sent_until_now = email_count | |
item = RareBook.last | |
visit send("new_rare_book_phone_call_path", :title => item.to_url_param, :id => item.id) | |
fill_in "phone_call_name", :with => "User name" | |
fill_in "phone_call_phone_number", :with => "1234567890" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MM_ITEMS.each do |item_type| | |
scope "#{item_type.to_s.pluralize}" do | |
# index items of item_type | |
match "/" => "items/#{item_type.to_s.pluralize}#index", :as => "#{item_type.to_s.pluralize}" | |
# show item | |
match ":title/:id" => "items/#{item_type.to_s.pluralize}#show", :as => "#{item_type.to_s}" | |
# shipping costs for item | |
get ":title/:id/shipping_costs" => "items/#{item_type.to_s.pluralize}#shipping_costs", :as => "#{item_type.to_s}_shipping_costs" | |
# question for item | |
get ":title/:id/new_question" => "items/#{item_type.to_s.pluralize}#new_question", :as => "new_#{item_type.to_s}_question" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mmplus | |
module Controllers | |
module Search | |
extend ActiveSupport::Concern | |
included do | |
before_filter :fix_params | |
def do_search(search_params, classes = nil) | |
q = search_params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Items::RareBooksController < Items::ItemsController | |
include Mmplus::Controllers::Items | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mmplus | |
module Controllers | |
module Items | |
extend ActiveSupport::Concern | |
included do | |
before_filter :set_instance | |
def index | |
do_search(params[:search] || {}, @instance) | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mmplus | |
module Models | |
autoload :Items, 'mmplus/models/items.rb' | |
autoload :Askable, 'mmplus/models/askable.rb' | |
autoload :Profile, 'mmplus/models/profile.rb' | |
autoload :ShippingCosts, 'mmplus/models/shipping_costs.rb' | |
autoload :BookshopConstraints, 'mmplus/models/bookshop_constraints.rb' | |
end | |
module Controllers | |
autoload :Search, 'mmplus/controllers/search.rb' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def to_query_params | |
words = [] | |
self.split(/\W/).each do |word| | |
words << "%#{word}%" | |
end | |
return words | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ItemImage < ActiveRecord::Base | |
belongs_to :item, :polymorphic => true | |
mount_uploader :image, ImageUploader | |
scope :the_cover, where(:cover => true) | |
end | |
class Book < ActiveRecord::Base | |
has_many :item_images, :as => :item | |
end |