Search Results

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

Page 103/378 | < Previous Page | 99 100 101 102 103 104 105 106 107 108 109 110  | Next Page >

  • jquerry in rails

    - by Matthias Günther
    I'm iteration over records and want to create the toggle-options for records but I can't replace the div-id with the records: <% for bill in @bills % <% tmp = "test"% <%= link_to '&raquo now','#', :onclick = '$("#{tmp}").toggle();' % Instead of getting: &raquo now I'm getting: &raquo now So he isn't evaluation the ruby variable in the string. How can I do this? Thanks for your help and I'm new in jquerry.

    Read the article

  • Rails: render a partial from a plugin

    - by Sam
    I'm getting a missing template error after I try rendering a partial from a plugin. I have included the files with the following: %w{ models controllers helpers views }.each do |dir| path = File.join(File.dirname(__FILE__), 'app', dir) $LOAD_PATH << path ActiveSupport::Dependencies.load_paths << path ActiveSupport::Dependencies.load_once_paths.delete(path) end The Models are getting loaded, but as for other things I'm not sure what's going on. The helpers are not getting loaded too because I just copied the contents of the partial from the plugin instead of the render :partial = and then it came up with a helper error. Question is how to be able to :render :partial = from the views folder in my plugin

    Read the article

  • Rails redirections with new users and logins

    - by Kenji Crosland
    So I'm trying to get the user to return to the page they were looking at before they click "log in" This is what I got in my user application controller: def redirect_back_or_default(default) redirect_to(session[:return_to] || default) session[:return_to] = nil end And this is what I have in my sessions controller: def new @user_session = UserSession.new session[:return_to] = request.referer end end def create @user_session = UserSession.new(params[:user_session]) if @user_session.save flash[:notice] = "Login successful!" redirect_back_or_default(home_path) else render :action => :new end end This works fine most of the time but if a user logs in right after they register to the site, they will get redirected to a blank page. I imagine this is the "create" action because it was the last action before going to user sessions new. So I tried this: def new @user_session = UserSession.new unless request.referer == join_path session[:return_to] = request.referer end end And this tries to take me back to the login page after I log in. What I'd really like to do is have the user see their profile when they log in for the very first time. This wouldn't give me a user id and raised a routing error def create @user_session = UserSession.new(params[:user_session]) if @user_session.save flash[:notice] = "Login successful!" redirect_back_or_default(user_path(current_user)) else render :action => :new end end Anybody gone through these redirecting acrobatics before? I can't seem to get it to work. I'm using authlogic if that helps.

    Read the article

  • Interaction between C++ and Rails applications

    - by FancyDancy
    I have two applications: c++ service and a RoR web server (they are both running at same VPS) I need to "send" some variables (and then do something with them) from each other. For exaple, i'm looking for something like this: // my C++ sample void SendMessage(string message) { SendTo("127.0.0.1", message); } void GetMessage(string message) { if (message == "stop") SendMessage("success"); } # Ruby sample # application_controller.rb def stop @m = Messager.new @m.send("stop") end I have never used it before, and i even don't know which technology should i search and learn.

    Read the article

  • need an empty string, but getting an exception in ruby on rails

    - by Jon
    controller @articles = current_user.articles view <% @articles.each do |article| %> <%= link_to "#{article.title} , #{article.author.name}" articles_path%> <% end %> Sometimes the article has no author, so is null in the database, which results in the following error You have a nil object when you didn't expect it! The error occurred while evaluating nil.name I still want to output the article title in this scenario, whats the best way to do this please?

    Read the article

  • Disable validation in an object in Ruby on Rails

    - by J. Pablo Fernández
    I have an object which whether validation happens or not should depend on a boolean, or in another way, validation is optional. I haven't found a clean way to do it. What I'm currently doing is this (disclaimer: you cannot unsee, leave this page if you are too sensitive): def valid? if perform_validation super else super # Call valid? so that callbacks get called and things like encrypting passwords and generating salt in before_validation actually happen errors.clear # but then clear the errors true # and claim ourselves to be valid. This is super hacky! end end Any better ways? Before you point to the :if argument of many validations, this is for a user model which is using authlogic so it has a lot of validation rules. You can stop reading here if you belive me. If you don't, authlogic already sets some :ifs like: :if => :email_changed? which I have to turn into :if => Proc.new {|user| user.email_changed? and user.perform_validation} and in some other cases, since I'm also using authlogic-oid (OpenID) I just don't have control over the :if, authlogic-oid sets it in a way I cannot change it (in time) without further monkey patching. So I have to override seemingly unrelated functions, catch exceptions if a method doesn't exist, etc. The previous hacky solution if the best of my two attempts.

    Read the article

  • and or operator in validates_presence_of of a Ruby on Rails model

    - by user284194
    I have an entry.rb model and I'm trying to make a semi-complicated validation. I want it to require one or more of the following fields: phone, phone2, mobile, fax, email or website. How would you write the intended code? Would something like this work? validates_presence_of :phone and or :phone2 and or :mobile and or :fax and or :email and or :website

    Read the article

  • How to store private pictures and videos in Ruby on Rails

    - by TK
    Here's a story: User A should be able to upload an image. User A should be able to set a privacy. ("Public" or "Private"). User B should not be able to access "Private" images of User A. I'm planning to user Paperclip for dealing with uploads. If I store the images under "RAILS_ROOT/public/images", anyone who could guess the name of the files might access the files. (e.g., accessing http://example.com/public/images/uploads/john/family.png ) I need to show the images using img tags, so I cannot place a file except public. How can I ensure that images of a user or group is not accessible by others?

    Read the article

  • Multiple robots.txt for subdomains in rails

    - by Christopher
    I have a site with multiple subdomains and I want the named subdomains robots.txt to be different from the www one. I tried to use .htaccess, but the FastCGI doesn't look at it. So, I was trying to set up routes, but it doesn't seem that you can't do a direct rewrite since every routes needs a controller: map.connect '/robots.txt', :controller => ?, :path => '/robots.www.txt', :conditions => { :subdomain => 'www' } map.connect '/robots.txt', :controller => ?, :path => '/robots.club.txt' What would be the best way to approach this problem? (I am using the request_routing plugin for subdomains)

    Read the article

  • Creating a gallery in Rails

    - by raphael_turtle
    I'm creating a simple site with a gallery. I have a photos model which has a page for each photo with it's info and an image. I'm unsure how to create a gallery from the photo's. The gallery model has_many photos, the photos model has_and_belongs_to_many galleries. I thought of adding a gallery.title field on each photo page so I'd have a list of photo's for each gallery then display them in a view. Is this a good way to make a gallery? (I've looked through the code on some gallery apps on github, but most are outdated are too complicated for my needs.)

    Read the article

  • Rails find_or_create by more than one attribute?

    - by tybro0103
    There is a handy dynamic attribute in active-record called find_or_create_by: Model.find_or_create_by_<attribute>(:<attribute> => "") But what if I need to find_or_create by more than one attribute? Say I have a model to handle a M:M relationship between Group and Member called GroupMember. I could have many instances where member_id = 4, but I don't ever want more than once instance where member_id = 4 and group_id = 7. I'm trying to figure out if it's possible to do something like this: GroupMember.find_or_create(:member_id => 4, :group_id => 7) I realize there may be better ways to handle this, but I like the convenience of the idea of find_or_create.

    Read the article

  • Apache/Rails/Passenger directory URLs that don't end in '/' fail to 404.

    - by Portamento
    I'm using Apache with passenger to run a rails app. In my rails app, I have some static content in subdirectories of the public directory. Each subdirectory has an index.html in it. So, inside the public directory, I have a subdir called 'b' and inside it, is an index.html. So it's like this: /public/b/index.html I have links to these pages, of the form: http://a.com/b If I do this in my regular non-rails web directory, Apache correctly rewrites this URL to be http://a.com/b/ which then, subsequently shows the index.html. It's only when accessing my rails app that it doesn't work. In fact, if I turn off passenger mod... so it just accesses my rails app like a regular document root, it works correctly also. What the heck do I need to do to get this to work properly with passenger? Again, it works fine in apache itself when passenger is not involved. I am running passenger 2.1.3. I have another server running passenger 2.0 that doesn't seem to have this problem, but I don't see anything different in the config other than the different versions of passenger itself. HELP! Been working on this for two days solid with no improvement!

    Read the article

  • rails Rake and mysql ssh port forwarding.

    - by rube_noob
    Hello, I need to create a rake task to do some active record operations via a ssh tunnel. The rake task is run on a remote windows machine so I would like to keep things in ruby. This is my latest attempt. desc "Syncronizes the tablets DB with the Server" task(:sync => :environment) do require 'rubygems' require 'net/ssh' begin Thread.abort_on_exception = true tunnel_thread = Thread.new do Thread.current[:ready] = false hostname = 'host' username = 'tunneluser' Net::SSH.start(hostname, username) do|ssh| ssh.forward.local(3333, "mysqlhost.com", 3306) Thread.current[:ready] = true puts "ready thread" ssh.loop(0) { true } end end until tunnel_thread[:ready] == true do end puts "tunnel ready" Importer.sync rescue StandardError => e puts "The Database Sync Failed." end end The task seems to hang at "tunnel ready" and never attempts the sync. I have had success when running first a rake task to create the tunnel and then running the rake sync in a different terminal. I want to combine these however so that if there is an error with the tunnel it will not attempt the sync. This is my first time using ruby Threads and Net::SSH forwarding so I am not sure what is the issue here. Any Ideas!? Thanks

    Read the article

  • rails expiring cache

    - by ash34
    Hi, I entered some products data into a table using a migration. I need to expire the page and fragment cache when I update, add, delete products from this table. I created a sweeper for this. class ProductSweeper < ActionController::Caching::Sweeper observe Product def after_create expire_cache end def after_save expire_cache end def after_update expire_cache end def after_destroy expire_cache end private def expire_cache expire_page(:controller => 'ProductsController', :action => 'index') expire_fragment 'listed_products' end end Then in script/console I update the product name and saved. When I reload my app in the browser it still gives me a cache hit. Cached fragment hit: views/listed_products (0.2ms) Can someone tell me how to expire this cache. I will not be adding, updating, deleting products through a controller action. thanks, ash

    Read the article

  • Group and sort blog posts by date in Rails

    - by Senthil
    I've searched all over web and have not found the answer. I'm trying to have a very standard archive option for my blog based on date. A request to url blog.com/archive/2009 shows all posts in 2009, blog.com/archive/2009/11 shows all posts in November 2009 etc. I found two different of code but not very helpful to me. def display_by_date year = params[:year] month = params[:month] day = params[:day] day = '0'+day if day && day.size == 1 @day = day if (year && month && day) render(:template => "blog/#{year}/#{month}/#{date}") elsif year render(:template => "blog/#{year}/list") end end def archive year = params[:year] month = params[:month] day = params[:day] day = '0'+day if day && day.size == 1 if (year && month && day) @posts_by_month = Blog.find(:all, :conditions => ["year is?", year]) else @posts_by_month = Blog.find(:all).group_by { |post| post.created_at.strftime("%B") } end end Any help is appreciated.

    Read the article

  • Sending emails based on intervals using Ruby on Rails

    - by Angela
    Hi, I would like to be able to send a string of emails at a determined interval to different recipients. I assign to each Contact this series of Emails called a Campaign, where Campaign has Email1, Email2, etc. Each Contact has a Contact.start_date. Each Email has email.days which stores the number of days since a Contact's start-date to send the email. For example: Email1.days=5, Email2.days=7, Email3.days=11. Contact1.start_date = 4/10/2010; contact2.start_date = 4/08/2010 IF today is 4/15, then Contact1 receives Email 1 (4/15-4/10 = 5 days) IF today is 4/15, then Contact2 received Email 2 (4/15 - 4/8 = 7 days). What's a good action to run every day using a cron job that would then follow these rules to send out emails using ActionMailer? Thanks.

    Read the article

  • Nested routing in Ruby on Rails

    - by vooD
    My model class is: class Category < ActiveRecord::Base acts_as_nested_set has_many :children, :foreign_key => "parent_id", :class_name => 'Category' belongs_to :parent, :foreign_key => "parent_id", :class_name => 'Category' end def to_param slug end Is it possible to have such recursive route like this: /root_category_slug/child_category_slug/child_of_a_child_category_slug ... and so one Thank you for any help :)

    Read the article

  • DRYing up Rails Views with Nested Resources

    - by viatropos
    What is your solution to the problem if you have a model that is both not-nested and nested, such as products: a "Product" can belong_to say an "Event", and a Product can also just be independent. This means I can have routes like this: map.resources :products # /products map.resources :events do |event| event.resources :products # /events/1/products end How do you handle that in your views properly? Note: this is for an admin panel. I want to be able to have a "Create Event" page, with a side panel for creating tickets (Product), forms, and checking who's rsvp'd. So you'd click on the "Event Tickets" side panel button, and it'd take you to /events/my-new-event/tickets. But there's also a root "Products" tab for the admin panel, which could list tickets and other random products. The 'tickets' and 'products' views look 90% the same, but the tickets will have some info about the event it belongs to. It seems like I'd have to have views like this: products/index.haml products/show.haml events/products/index.haml events/products/show.haml But that doesn't seem DRY. Or I could have conditionals checking to see if the product had an Event (@product.event.nil?), but then the views would be hard to understand. How do you deal with these situations? Thanks so much.

    Read the article

  • Using URI-fragments in Ruby on rails routing

    - by Alexei
    RoR application can generate URL such as /post/10. But now I want to create a site, which works with URI-fragments like gmail. For example gmail uses the following URLs https://mail.google.com/mail/?shva=1#sent https://mail.google.com/mail/?shva=1#label/books I need to generate URL such as /#/post/10, where controller = "post", action = "show", id = "10". Of course it will be good to use standard url-helpers.

    Read the article

  • Rails - Accessing model class methods from within ActiveRecord model

    - by aaronrussell
    I have a simple standalone model that doesn't inherit from ActiveRecord or anything else, called SmsSender. As the name suggests, it delivers text messages to an SMS gateway. I also have an ActiveRecord model called SmsMessage which has an instance method called deliver: def deliver SmsSender.deliver_message(self) self.update_attributes :status => "Sent" end The above is returning uninitialized constant SmsSender. I'm sure this is dead simple, but how can I access the SmsSender class from within my model?

    Read the article

  • Nest input inside f.label ( rails form generation )

    - by Mike
    I want to use the f.label method to create my form element labels, however - i want to have the form element nested inside the label. Is this possible? -- From W3C -- To associate a label with another control implicitly, the control element must be within the contents of the LABEL element. In this case, the LABEL may only contain one control element. The label itself may be positioned before or after the associated control. In this example, we implicitly associate two labels with two text input controls: <FORM action="..." method="post"> <P> <LABEL> First Name <INPUT type="text" name="firstname"> </LABEL> <LABEL> <INPUT type="text" name="lastname"> Last Name </LABEL> </P> </FORM>

    Read the article

  • How to test the XML sent to a web service in Ruby/Rails

    - by Jason Langenauer
    I'm looking for the best way to write unit test for code that POSTs to an external web service. The body of the POST request is an XML document which describes the actions and data for the web service to perform. Now, I've wrapped the webservice in its own class (similar to ActiveResource), and I can't see any way to test the exact XML being generated by the class without breaking encapsulation by exposing some of the internal XML generation as public methods on the class. This seems to be a code smell - from the point-of-view of the users of the class, they should not know, nor care, how the class actually implements the web service call, be it with XML, JSON or carrier pigeons. For an example of the class: class Resource def new #initialize the class end def save! Http.post("http://webservice.com", self.to_xml) end private def to_xml # returns an XML representation of self end end I want to be able to test the XML generated to ensure it conforms to what the specs for the web service are expecting. So can I best do this, without making to_xml a public method?

    Read the article

  • Scalability of Ruby on Rails versus PHP

    - by Daniel
    Can anyone comment on which is more scalable between RoR and PHP? I have heard that RoR is less scalable than PHP since RoR has a little more overhead with its MVC framework while PHP is more low level and lighter. This is a bit vague - can anyone explain better?

    Read the article

  • Grouped Select in Rails

    - by Neil Middleton
    Simple question really - how do I use the select(ActionView::Helpers::FormOptionsHelper) with grouped options? I have got it working with a select_tag (ActionView::Helpers::FormTagHelper) but I would really like to have it using a select tag to match the rest of the form. Is this possible? My options look like this: [ ['Group 1', ["Item 1", "Item 2", "Item 3"]], ['Group 2',["Item 1", "Item 2", "Item 3", "Item 4"]] ] whilst my view is currently: %tr#expense %td = f.text_field :value = f.hidden_field :type, :value => mode

    Read the article

< Previous Page | 99 100 101 102 103 104 105 106 107 108 109 110  | Next Page >