Search Results

Search found 9437 results on 378 pages for 'rails newbie'.

Page 51/378 | < Previous Page | 47 48 49 50 51 52 53 54 55 56 57 58  | Next Page >

  • Dynamically defined setter methods using define_method?

    - by nicosuria
    I use a lot of iterations to define convenience methods in my models, stuff like: PET_NAMES.each do |pn| define_method(pn) do ... ... end but I've never been able to dynamically define setter methods, ie: def pet_name=(name) ... end using define_method like so: define_method("pet_name=(name)") do ... end Any ideas? Thanks in advance.

    Read the article

  • Acts as Tree with Multiple Models

    - by Joe
    I've got several models that I'd like to relate together hierarchically. For simplicity's sake, let's say I've got these three: class Group < ActiveRecord::Base acts_as_tree has_many :users end class User < ActiveRecord::Base acts_as_tree belongs_to :group has_many :posts end class Post < ActiveRecord::Base acts_as_tree belongs_to :user end Under the current acts_as_tree, each node can individually can relate hierarchically to other nodes provided they are of the same type. What I'd like is to remove this restriction on type identity, so that SomePost.parent could have a User or a Post as its' parent, and that SomeUser.parent could have another user or a group as its parent. Any thoughts?

    Read the article

  • Delete records from table which matches the data in an array?

    - by Maxsy
    I have a table of 2 fields. Word and timestamp. Then i have this array which contains some words. How do i delete all the records in the table which match with the words in the array? Suppose that the model is called "Word". Any ideas on how to achieve this? maybe loop through the array and run some destroy queries. Can anybody direct me here? thanks

    Read the article

  • OpenID Authentication using AuthLogic Error

    - by Steve
    Hi, I am trying to implement openid authentication using authlogic. I have installed the open_id_authentication in the process but when I entered rake open_id_authentication:db:create --trace I get the following error (in /Users/felix/login) rake aborted! Don't know how to build task 'open_id_authentication:db:create' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1728:in `[]' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2050:in `invoke_task' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>' /usr/local/bin/rake:19:in `load' /usr/local/bin/rake:19:in `<main>' Can someone tell what am i doing incorrectly Thanks

    Read the article

  • Find model records by ID in the order the array of IDs were given

    - by defaye
    I have a query to get the IDs of people in a particular order, say: ids = [1, 3, 5, 9, 6, 2] I then want to fetch those people by Person.find(ids) But they are always fetched in numerical order, I know this by performing: people = Person.find(ids).map(&:id) => [1, 2, 3, 5, 6, 9] How can I run this query so that the order is the same as the order of the ids array? I made this task more difficult as I wanted to only perform the query to fetch people once, from the IDs given. So, performing multiple queries is out of the question. I tried something like: ids.each do |i| person = people.where('id = ?', i) But I don't think this works.

    Read the article

  • Multiple inputs on a single line with Twitter Bootstrap and Simple Form 2.0

    - by noel_g
    I am using simple_form 2.0 with twitter bootstrap. I am trying to determine what is the proper wrapper format in order to get something like [city] [State] [Zip] I believe my form needs to be <div class="control-group"> <%= f.input :city,:wrapper => :small, :placeholder => "City", :input_html => { :class=>"span2", :maxlength => 10},:label => false %> <%= f.input :region, :wrapper => :small , :placeholder => "Region", :input_html => { :class=>"span1", :maxlength => 5}, :label => false %> <%= f.input :postal_code, :wrapper => :small, :placeholder => "Postal Code",:input_html => { :class=>"span2", :maxlength => 10},:label => false %> </div> I tried this wrapper config.wrappers :small, :tag => 'div', :class => 'controls inline-inputs', :error_class => 'error' do |b| b.use :placeholder b.use :label_input end I believe I would need to define the CSS as well, but before I go down a rabbit hole I thought I would ask if this is built in somewhere.

    Read the article

  • Can't mass-assign protected attributes: user

    - by Ben Aluan
    I'm working on a simple app that requires me to submit a form. I created two models. user.rb class User < ActiveRecord::Base attr_accessible :email has_many :item end item.rb class Item < ActiveRecord::Base attr_accessible :user_id belongs_to :user end Instead of creating a user using the user form view, I'm trying to create the user using the item form view. items/_form.html.haml = nested_form_for @item do |form| = form.fields_for :user do |builder| = builder.text_field :email = form.submit "Save" Did I miss something here? I'm using nested_form_for btw. Thank you.

    Read the article

  • VirtualHost problem with passenger (mod_rails)

    - by Jake
    Hi all, I'm at my wit's end here with virtual hosting. I'm trying to install redmine and it works with the webrick test server, but when I tried to use passenger (mod_rails) to host and go to the address I specified when in the virtualhost part of my apache config file nothing happens. Here is the relavent section of /etc/httpd/conf/httpd.conf where I try to set up the virtual host: <VirtualHost *:80> SetEnv RAILS_ENV production ServerName redmine.MYSITE.com:80 DocumentRoot /opt/redmine-1.0.5/public/ <Directory /opt/redmine-1.0.5/public/> Options -MultiViews Allow from all AllowOverride none </Directory> However, when I got to redmine.MYSITE.com:80 nothing happens, I just get our normal home page. I have no idea what the problem is, any help our guidance would be greatly appreciated. If you need any other information, please tell me and I'll provide it.

    Read the article

  • Omniauth + Pow Issue

    - by neon
    I am having a strange issue with Pow and Omniauth. Omniauth (Facebook Login) works fine when using localhost:3000, but when using Pow (appname.dev) things get fishy. Users are taken through the redirect and properly created if they don't exist in the database, as they should be. After this, however, they are redirected to the root_path and not signed in. Their record is saved in the database as expected, but sign in does not occur. Again, this is only happening on Pow (and lvh.me), and not on localhost. Any ideas? I am using the Devise/Omniauth approach for sign-in, and the controller code looks like this: def facebook @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user) if @user.persisted? flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook" sign_in_and_redirect @user, :event => :authentication else session["devise.facebook_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url end end Again, the user is persisted but there is no flash notice or sign_in that occurs when using POW.

    Read the article

  • ROR accepts_nested_attributes_for one to many relationship with selection

    - by bilash.saha
    I have two models Doctors and Questions like the follwong: Doctor Model class Doctor < ActiveRecord::Base has_many :questions has_many :brands accepts_nested_attributes_for :questions end Question model class Question < ActiveRecord::Base belongs_to :discipline belongs_to :doctor belongs_to :brand end Now you can clearly see that Doctor has many questions and brands and question belongs to doctor and brand.I want to add previously saved question to a doctor from doctors edit page. I want to remove them as well.How can I proceed ? I tried like : <%= form.fields_for :questions, question,:child_index => (question.new_record? ? "index_to_replace_with_js" : nil) do |question_form| %> <table> <tr> <td> <div class="label">Select Question</div> <%= question_form.collection_select :id, Question.all, :id, :title ,{:include_blank => true } %> </td> </tr> </table> but this doesnot works for me.Can you give me a solution with proper example ?

    Read the article

  • Search function fails because it refers to the wrong controller action?

    - by Christoffer
    My Sunspot search function (sunspot_rails gem) works just fine in my index view, but when I duplicate it to my show view my search breaks... views/supplierproducts/show.html.erb <%= form_tag supplierproducts_path, :method => :get, :id => "supplierproducts_search" do %> <p> <%= text_field_tag :search, params[:search], placeholder: "Search by SKU, product name & EAN number..." %> </p> <div id="supplierproducts"><%= render 'supplierproducts' %></div> <% end %> assets/javascripts/application.js $(function () { $('#supplierproducts th a').live('click', function () { $.getScript(this.href); return false; } ); $('#supplierproducts_search input').keyup(function () { $.get($("#supplierproducts_search").attr("action"), $("#supplierproducts_search").serialize(), null, 'script'); return false; }); }); views/supplierproducts/show.js.erb $('#supplierproducts').html('<%= escape_javascript(render("supplierproducts")) %>'); views/supplierproducts/_supplierproducts.hmtl.erb <%= hidden_field_tag :direction, params[:direction] %> <%= hidden_field_tag :sort, params[:sort] %> <table class="table table-bordered"> <thead> <tr> <th><%= sortable "sku", "SKU" %></th> <th><%= sortable "name", "Product name" %></th> <th><%= sortable "stock", "Stock" %></th> <th><%= sortable "price", "Price" %></th> <th><%= sortable "ean", "EAN number" %></th> </tr> </thead> <% for supplierproduct in @supplier.supplierproducts %> <tbody> <tr> <td><%= supplierproduct.sku %></td> <td><%= supplierproduct.name %></td> <td><%= supplierproduct.stock %></td> <td><%= supplierproduct.price %></td> <td><%= supplierproduct.ean %></td> </tr> </tbody> <% end %> </table> controllers/supplierproducts_controller.rb class SupplierproductsController < ApplicationController helper_method :sort_column, :sort_direction def show @supplier = Supplier.find(params[:id]) @search = @supplier.supplierproducts.search do fulltext params[:search] end @supplierproducts = @search.results end end private def sort_column Supplierproduct.column_names.include?(params[:sort]) ? params[:sort] : "name" end def sort_direction %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc" end models/supplierproduct.rb class Supplierproduct < ActiveRecord::Base attr_accessible :ean, :name, :price, :sku, :stock, :supplier_id belongs_to :supplier validates :supplier_id, presence: true searchable do text :ean, :name, :sku end end Visiting show.html.erb works just fine. Log shows: Started GET "/supplierproducts/2" for 127.0.0.1 at 2012-06-24 13:44:52 +0200 Processing by SupplierproductsController#show as HTML Parameters: {"id"=>"2"} Supplier Load (0.1ms) SELECT "suppliers".* FROM "suppliers" WHERE "suppliers"."id" = ? LIMIT 1 [["id", "2"]] SOLR Request (252.9ms) [ path=#<RSolr::Client:0x007fa5880b8e68> parameters={data: fq=type%3ASupplierproduct&start=0&rows=30&q=%2A%3A%2A, method: post, params: {:wt=>:ruby}, query: wt=ruby, headers: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, path: select, uri: http://localhost:8982/solr/select?wt=ruby, open_timeout: , read_timeout: } ] Supplierproduct Load (0.2ms) SELECT "supplierproducts".* FROM "supplierproducts" WHERE "supplierproducts"."id" IN (1) Supplierproduct Load (0.1ms) SELECT "supplierproducts".* FROM "supplierproducts" WHERE "supplierproducts"."supplier_id" = 2 Rendered supplierproducts/_supplierproducts.html.erb (2.2ms) Rendered supplierproducts/show.html.erb within layouts/application (3.3ms) Rendered layouts/_shim.html.erb (0.0ms) User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'zMrtTbDun2MjMHRApSthCQ' LIMIT 1 Rendered layouts/_header.html.erb (2.1ms) Rendered layouts/_footer.html.erb (0.2ms) Completed 200 OK in 278ms (Views: 20.6ms | ActiveRecord: 0.6ms | Solr: 252.9ms) But it breaks when I type in a search. Log shows: Started GET "/supplierproducts?utf8=%E2%9C%93&search=a&direction=&sort=&_=1340538830635" for 127.0.0.1 at 2012-06-24 13:53:50 +0200 Processing by SupplierproductsController#index as JS Parameters: {"utf8"=>"?", "search"=>"a", "direction"=>"", "sort"=>"", "_"=>"1340538830635"} Rendered supplierproducts/_supplierproducts.html.erb (2.4ms) Rendered supplierproducts/index.js.erb (2.9ms) Completed 500 Internal Server Error in 6ms ActionView::Template::Error (undefined method `supplierproducts' for nil:NilClass): 10: <th><%= sortable "ean", "EAN number" %></th> 11: </tr> 12: </thead> 13: <% for supplierproduct in @supplier.supplierproducts %> 14: <tbody> 15: <tr> 16: <td><%= supplierproduct.sku %></td> app/views/supplierproducts/_supplierproducts.html.erb:13:in `_app_views_supplierproducts__supplierproducts_html_erb___2251600857885474606_70174444831200' app/views/supplierproducts/index.js.erb:1:in `_app_views_supplierproducts_index_js_erb___1613906916161905600_70174464073480' Rendered /Users/Computer/.rvm/gems/ruby-1.9.3-p194@myapp/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (33.3ms) Rendered /Users/Computer/.rvm/gems/ruby-1.9.3-p194@myapp/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms) Rendered /Users/Computer/.rvm/gems/ruby-1.9.3-p194@myapp/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (39.7ms)

    Read the article

  • Multiple tables on one page with prawn

    - by Ignace
    Hey, I'm using prawn for pdf generation and everything works quite well, but now I'm having a bit of a problem. When I put multiple tables on one page, they just get put over each other and not under each other. Is this normal behaviour and what can I do about it? I add the tables on the most normal behaviour btw :) Thanks!

    Read the article

  • Generating URLs when not using an integer as an id?

    - by Synthesezia
    So I'm building a blog engine which has /articles/then-the-article-permalink as it's URL structure. I need to have prev and next links which will jump to the next article by pub_date, my code looks like this: In my articles#show @article = Article.find_by_permalink(params[:id]) @prev_article = Article.find(:first, :conditions => [ "pub_date < ?", @article.pub_date]) @next_picture = Article.find(:first, :conditions => [ "pub_date > ?", @article.pub_date]) And in my show.html.erb <%= link_to "Next", article_path(@next_article) %> <%= link_to 'Prev', article_path(@prev_article) %> In my articles model I have this: def to_param self.permalink end The specific error message I get is: article_url failed to generate from {:action=>"show", :controller=>"articles", :id=>nil}, expected: {:action=>"show", :controller=>"articles"}, diff: {:id=>nil} Without the prev and next everything is working fine but I'm out of ideas as to why this isn't working. Anyone want to helo?

    Read the article

  • Passing Values to Controllers

    - by Dru
    I'm trying to allow users to 'favorite' links (that is, create a new Favorite record with their user_id and the link_id) This is what I have so far.. When I click favorite (as a user), the new record is assigned to the user_id but the link_id field is nil. How can I pass the link_id into my FavoritesController? My View Code Added Link Model Code class FavoritesController < ApplicationController def create @user = User.find(session[:user_id]) @favorite = @user.favorites.create :link_id => params[:id] redirect_to :back end end The Favorite model belongs to :user and :link Note: I've also tried this but when I click 'favorite', there's an error "Couldn't find Link without an ID." Update <%= link_to "Favorite", :controller => :favorites, :action => :create, :link_id => link.id %> with class FavoritesController < ApplicationController def create @user = User.find(session[:user_id]) @favorite = @user.favorites.create :link_id => :params[:link_id] redirect_to :back end end Returns "can't convert Symbol into Integer" app/controllers/favorites_controller.rb:4:in [] app/controllers/favorites_controller.rb:4:in create I've tried forcing it into an Integer several ways with .to_i

    Read the article

  • Nested attributes form for model which belongs_to few models

    - by ExiRe
    I have few models - User, Teacher and TeacherLeader. class User < ActiveRecord::Base attr_accessible ..., :teacher_attributes has_one :teacher has_one :teacher_leader accepts_nested_attributes_for :teacher_leader end class Teacher < ActiveRecord::Base belongs_to :user has_one :teacher_leader end class TeacherLeader < ActiveRecord::Base belongs_to :user belongs_to :teacher end I would like to fill TeacherLeader via nested attributes. So, i do such things in controller: class TeacherLeadersController < ApplicationController ... def new @user = User.new @teacher_leader = @user.build_teacher_leader @teachers_collection = Teacher.all.collect do |t| [ "#{t.teacher_last_name} #{t.teacher_first_name} #{t.teacher_middle_name}", t.id ] end @choosen_teacher = @teachers_collection.first.last unless @teachers_collection.empty? end end And also have such view (new.html.erb): <%= form_for @user, :url => teacher_leaders_url, :html => {:class => "form-horizontal"} do |f| %> <%= field_set_tag do %> <% f.fields_for :teacher_leader do |tl| %> <div class="control-group"> <%= tl.label :teacher_id, "Teacher names", :class => "control-label" %> <div class="controls"> <%= select_tag( :teacher_id, options_for_select( @teachers_collection, @choosen_teacher )) %> </div> </div> <% end %> <div class="control-group"> <%= f.label :user_login, "Login", :class => "control-label" %> <div class="controls"> <%= f.text_field :user_login, :placeholder => @everpresent_field_placeholder %> </div> </div> <div class="control-group"> <%= f.label :password, "Pass", :class => "control-label" %> <div class="controls"> <%= f.text_field :password, :placeholder => @everpresent_field_placeholder %> </div> </div> <% end %> <%= f.submit "Create", :class => "btn btn-large btn-success" %> <% end %> Problem is that select form here does NOT appear. Why? Do i do something wrong?

    Read the article

  • Nested Resource testing RSpec

    - by Joseph DelCioppio
    I have two models: class Solution < ActiveRecord::Base belongs_to :owner, :class_name => "User", :foreign_key => :user_id end class User < ActiveRecord::Base has_many :solutions end with the following routing: map.resources :users, :has_many => :solutions and here is the SolutionsController: class SolutionsController < ApplicationController before_filter :load_user def index @solutions = @user.solutions end private def load_user @user = User.find(params[:user_id]) unless params[:user_id].nil? end end Can anybody help me with writing a test for the index action? So far I have tried the following but it doesn't work: describe SolutionsController do before(:each) do @user = Factory.create(:user) @solutions = 7.times{Factory.build(:solution, :owner => @user)} @user.stub!(:solutions).and_return(@solutions) end it "should find all of the solutions owned by a user" do @user.should_receive(:solutions) get :index, :user_id => @user.id end end And I get the following error: Spec::Mocks::MockExpectationError in 'SolutionsController GET index, when the user owns the software he is viewing should find all of the solutions owned by a user' #<User:0x000000041c53e0> expected :solutions with (any args) once, but received it 0 times Thanks in advance for all the help. Joe

    Read the article

  • How to round down a DateTime value

    - by timpone
    I have a Location that can have Events. I want to have an upcoming_events method but want it to round down such that if someone looks at 10pm at night, it will show todays events. I have this: def upcoming_events d=Time.new d.strftime("%m-%d-%Y") l=Event.where('location_id=? and start_datetime>?',self.id, d) end I gets converted down correctly but in d.strftime but the query is: SELECT `events`.* FROM `events` WHERE (location_id=301 and start_datetime>'2012-06-20 02:49:23') Any idea how to just get it to do '2012-06-20'?

    Read the article

  • Why is the Twitter Bootstrap "fixed" layout NOT fixed?

    - by leonel
    The Twitter Bootstrap site reads as follows: The default and simple 940px-wide, centered layout for just about any website or page provided by a single <div class="container">. Quote from http://twitter.github.com/bootstrap/scaffolding.html#layouts That's exactly what I have in my HTML but when I inspect the element, I see this CSS apply to it: .container, .navbar-fixed-top .container, .navbar-fixed-bottom .container { width: 1170px; } By the way, if I override that CSS rule by adding... div.container{ width:940px; } Then the elements inside the div.container are wider than the div.container itself and look out of place. So, why is the Twitter Bootstrap "fixed" layout NOT fixed? and how can I make it fixed?

    Read the article

  • What is the difference between a restful route method for getting an index vs. creating a new object

    - by Jason
    According to rake routes, there's the same path for getting an index of objects as there is for creating a new object: cars GET /cars(.:format) {:controller=>"plugs", :what=>"car", :action=>"index"} POST /cars(.:format) {:controller=>"plugs", :what=>"car", :action=>"create"} Obviously, the HTTP verb is what distinguishes between them. I want the "create" version of the cars_path method, not the "index" version. My question is what route method do you invoke to choose the one you want? I'm telling cucumber what path to generate with this: when /the car plug preview page for "(.+)"/ cars_path(:action => :create, :method => :post) ...but it always chooses the "index" action, not "create". I've tried lots of combinations for the hash argument following cars_path and nothing changes it from choosing "index" instead of "create". I'll get an error like this: cars_url failed to generate from {:controller=>"plugs", :method=>:post, :what=>"car", :action=>"create"}, expected: {:controller=>"plugs", :what=>"car", :action=>"index"}, diff: {:method=>:post, :action=>"index"} (ActionController::RoutingError) This seems like a very simple question but I've had no luck googling for it, so could use some advice. Thanks.

    Read the article

  • Configuring Warden for use in RSpec controller specs

    - by Chris Peters
    I was able to use Devise's sign_in method to log in a user in my controller specs. But now that I'm removing Devise from my application, I'm not quite sure how to get similar functionality working with just Warden on its own. How should I go about setting up spec/spec_helper.rb and related spec/support/*.rb files to get Warden running within controller specs sufficiently? I've tried setting up a file at spec/support/warden.rb with these contents: RSpec.configure do |config| config.include Warden::Test::Helpers config.after do Warden.test_reset! end end Then I have before calls similar to this to authenticate a user factory: before { login_as FactoryGirl.create(:user) } But here is the error that I keep seeing: NameError: undefined method `user' for nil:NilClass This error traces back to my authenticate_user! method in the controller: def authenticate_user! redirect_to login_path, notice: "You need to sign in or sign up before continuing." if env['warden'].user.nil? end I'd appreciate any guidance that anyone could provide.

    Read the article

  • How do I find the user that has both a cat and a dog?

    - by brad
    I want to do a search across 2 tables that have a many-to-one relationship, eg class User << ActiveRecord::Base has_many :pets end class Pet << ActiveRecord::Base belongs_to :users end Now let's say I have some data like so users id name 1 Bob 2 Joe 3 Brian pets id user_id animal 1 1 cat 2 1 dog 3 2 cat 4 3 dog What I want to do is create an active record query that will return a user that has both a cat and a dog (i.e. user 1 - Bob). My attempt at this so far is User.joins(:pets).where('pets.animal = ? AND pets.animal = ?','dog','cat') Now I understand why this doesn't work - it's looking for a pet that is both a dog and a cat so returns nothing. I don't know how to modify this to give me the answer I want however. Does anyone have any suggestions? This seems like it should be easy - it doesn't seem like an especially unusual situation.

    Read the article

  • Help installing delayed_job

    - by Mike
    I'm trying to use collectiveidea's delayed_job gem The installation instructions include Rake tasks are not automatically loaded from gems, so you’ll need to add the following to your Rakefile: begin require 'delayed/tasks' rescue LoadError STDERR.puts "Run `rake gems:install` to install delayed_job" end Where is my Rakefile? And what is a Rakefile?

    Read the article

  • RoR: Output Hash, getting correct parameters?

    - by andrewliu
    I have output something like this: #<Hashie::Mash created_time="1366008641" from=#<Hashie::Mash full_name="Cor Valen" id="22340" username="_corin"> id="4344344286" text="Look Who It Is, My Brother, My Favorite Deputy"> This was an output if I did this: <%= media.caption %> I wanted to get the text part, and I did this: <%= media.caption.text %> gets me error: undefined method `text' for nil:NilClass <%= media.caption[:text] %> gets me error: undefined method `[]' for nil:NilClass I don't get it? Thanks

    Read the article

  • How to create factories with attr_accesible?

    - by regedarek
    How to deal with factories and attr_accessible? My example: # model class SomeModel attr_accessible :name, full_name, other_name end #spec require 'spec_helper' describe "test" do it do create(:some_model, name: "test name", user: User.first) #factory end end #error ruby(17122,0x12a055000) malloc: *** error for object 0x8: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug I think the error is because user_id is not in attr_accesible atributes

    Read the article

  • How to give the First image in a gallery a different class than the rest of the images - Carrierwave

    - by ChrisBedoya
    I have a model called "Photo" that belongs to a model called "Shoe". I using Carrierwave to upload multiple images. index.html.erb <% shoes.each do |shoe| %> <div class="shoe"> <div class="gallery"> <% shoe.photos.each do |photo| %> <%= link_to image_tag(photo.photo_file.url(:thumb).to_s), photo.photo_file.url.to_s, :class => 'fancybox', :rel => 'gallery' %> <% end %> </div> </div> <% end %> Outputs this: <div class="shoe"> <div class="gallery"> <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery"> <img src="../thumb_nike-kd-6-meteorology-2.jpg"> </a> <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery"> <img src="../thumb_nike-kd-6-meteorology-2.jpg"> </a> <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery"> <img src="../thumb_nike-kd-6-meteorology-2.jpg"> </a> </div> </div> But I want the first image of each gallery to be able to have its own class and the rest of the images to have their own class. Something like this: <a class="firstclass" href="../nike-kd-6-meteorology-2.jpg" rel="gallery"> <img src="../thumb_nike-kd-6-meteorology-2.jpg"> </a> <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery"> <img src="../thumb_nike-kd-6-meteorology-2.jpg"> </a> <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery"> <img src="../thumb_nike-kd-6-meteorology-2.jpg"> </a> How can I do this? Also I want each gallery to have its own unique id but when I try to add this: :rel => 'gallery<%= shoe.id %>' I get a Syntax error. Thanks.

    Read the article

< Previous Page | 47 48 49 50 51 52 53 54 55 56 57 58  | Next Page >