Search Results

Search found 9853 results on 395 pages for 'ruby datamapper'.

Page 17/395 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • Displaying most popular posts on my blog - Ruby on Rails

    - by bgadoci
    I have created a simple blog application using Ruby on Rails, both of which I am new to. I am trying to get my most 'voted' posts to display in my /views/posts/index.html.erb view. Here are the basics. I have created a votes table and successfully allow a user to 'vote' for a post on the /views/posts/show.html.erb page. When they vote, it passes '1' to the votes table and I return the vote count via ajax to the same show page. Vote belongs_to :post and Post has_many :votes. I would like to display in /views/posts/index.html.erb the post title and the amount of times it has been voted for, ordered by posts with the highest vote count. Any ideas on how to do this?

    Read the article

  • Ruby CMS/blog: Mephisto vs. Radiant

    - by Candidasa
    I'm looking for a blogging tool with some light CMS features in Ruby on Rails. I mainly want something simple, but configurable. I have no need for page snippets, etc. Just your basic main blog, very good (and easy) theme support, some nice sidebar stuff, a few static pages and MetaWeblog API support. I'm thinking of either using Mephisto or Radiant CMS (everything else seems half-baked or extremely lightweight at best): http://mephistoblog.com/ http://www.radiantcms.org/ Documentation for Mephisto seems very lacking and their site is a mess. I've also read some bad things about it's stability. Radiant seems more stable in comparison and has heaps of useful plug-ins. However, it isn't designed for blogging out of the box. That has to be added as almost an after thought. Creating a custom theme also seems more cumbersome with Radiant due to the sub-page/snippet feature. Which should I choose?

    Read the article

  • getting rid of ruby gems that won't die

    - by holden
    I've got a few ruby gems that won't go away. I think it has to do with when I installed them. Occasionally I have forgotten to use "sudo" before doing a gem install, which results in a write error and from what I can gather puts a copy of the gem in my user directory instead of somewhere it can run. But gem uninstall doesn't work. It continually shows up in 'gem list' but can't uninstall it from either gem uninstall, or sudo gem uninstall. I tried directly deleting one gem after finding the path in my 'gem environment', but that still left the gem on the list. Also is it possible just to remove all gems and start from scratch? These are driving me nuts. I'm running OS X. Thanks,

    Read the article

  • Learning Ruby on Rails

    - by Ethan Gunderson
    As it stands now I'm a Java and C# developer, but the more and more I look at Ruby on Rails, the more I really want to learn it. What have you found to be the best route to learn RoR? Would it be easier to develop on Windows, or should I just run a virtual machine with linux? Is there an ide that can match the robustness of Visual Studio? Any programs to develop that give a good overhead of what to do? Any good books? Seriously, any tips/tricks/rants would be awesome.

    Read the article

  • ruby syntactic sugar: dealing with nils..

    - by luca
    probably asked already but I couldn't find it.. here are 2 common situation (for me while programming rails..) that are frustrating to write in ruby: "a string".match(/abc(.+)abc/)[1] in this case I get an error because the string doesn't match, therefore the [] operator is called upon nil. What I'd like to find is a nicer alternative to the following: temp="a string".match(/abc(.+)abc/); temp.nil? ? nil : temp[1] in brief, if it didn't match simply return nil without the error The second situation is this one: var = something.very.long.and.tedious.to.write var = something.other if var.nil? In this case I want to assign something to var only if it's not nil, in case it's nil I'll assign something.other.. Any suggestion? Thanks!

    Read the article

  • Action Mailer Confirmation Emails - Ruby on Rails...

    - by bgadoci
    I have successfully installed the Clearance Gem from ThoughtBot. Clearance sends a confirmation email upon a new sign_up and suggests adding: config.action_mailer.default_url_options = { :host => 'localhost:3000' } to your /environments/test.rb and development.rb. I have tried this and also config.action_mailer.default_url_options = { :host => '127.0.0.1', :port => 3000 } But can't seem to get rails to send the email. As I am new to both Ruby and Rails, I am wondering if there is some step/config that ThoughtBot is assuming I have already done to send emails. What am I doing wrong/missing? UPDATE: Just added notifier.rb class Notifier < ActionMailer::Base recipients recipient.email_address_with_name bcc ["[email protected]"] from "[email protected]" subject "New account information" body :account => recipient end end

    Read the article

  • validating creation by post_id and ip_address - Ruby on Rails

    - by bgadoci
    I have created a blog application using Ruby on Rails which includes the ability to vote on posts. A user can click vote and a record is created in the vote table. I am now trying to limit that same person from voting for a post multiple times. class Post has_many :votes end class Vote belongs_to :post end When a vote record is created I am using the VotesController to pass the :post_id and using a hidden field in the view to pass the ip_address (both to the vote table). I am wondering if there is a way to add a validation to the Vote Model that searches to see if a post_id has an ip_address that matches the person requesting to vote. I have tried simply using the validates_uniqueness_of :ip_address but that restricts the user from voting on any post. I just want to restrict the user from voting on a particular post that they have already voted on. Is there a way to do this through validation?

    Read the article

  • Linking to external file in Ruby on Rails

    - by Maestro1024
    Linking to external file in Ruby on Rails I have a file I want to share as a link in my rails app. I create a link to it in the .erb file like this <li><a href="somefile.pdf">Some File</a> </li> When I select the link I get the following error. Routing Error No route matches "/pages/somefile.pdf" with {:method=:get} Do I really need a route for this? I really just want the save as dialog to popup. Just a link to a file that the user can open or download. What is the rails way to do this (rails newbie here)?

    Read the article

  • Ruby on Rails Join Table Associations

    - by Eef
    Hey, I have a Ruby on Rails application setup like so: User Model has_and_belongs_to_many :roles Role Model has_many :transactions has_and_belongs_to_many :users Transaction Model belongs_to :role This means that a join table is used called roles_users and it also means that a user can only see the transactions that have been assigned to them through roles, usage example: user = User.find(1) transactions = user.roles.first.transactions This will return the transactions which are associated with the first role assigned to the user. If a user has 2 roles assigned to them, at the moment to get the transactions associated with the second role I would do: transactions = user.roles.last.transactions I am basically trying to figure out a way to setup an association so I can grab the user's transactions via something like this based on the roles defined in the association between the user and roles: user = User.find(1) transactions = user.transactions I am not sure if this is possible? I hope you understand what I am trying to do.

    Read the article

  • A very basic issue with routes in ruby

    - by Haris
    I am new to ruby and while creating a sample application found out an issue that whenever I go to http://127.0.0.1:3000/people/index by default show action is executed and index is taken as a parameter. This is server log: Started GET "/people/index" for 127.0.0.1 at 2010-12-23 18:43:01 +0500 Processing by PeopleController#show as HTML Parameters: {"id"=>"index"} I have this in my route file: root :to => "people#index" resources> :people match ':controller(/:action(/:id(.:format)))' What is going on here and how can I fix the issue?

    Read the article

  • Ruby ways to authenticate using headers?

    - by webdestroya
    I am designing an API system in Ruby-on-Rails, and I want to be able to log queries and authenticate users. However, I do not have a traditional login system, I want to use an APIkey and a signature that users can submit in the HTTP headers in the request. (Similar to how Amazon's services work) Instead of requesting /users/12345/photos/create I want to be able to request /photos/create and submit a header that says X-APIKey: 12345 and then validate the request with a signature. Are there any gems that can be adapted to do that? Or better yet, any gems that do this without adaptation? Or do you feel that it would be wiser to just have them send the API key in each request using the POST/GET vars?

    Read the article

  • Ruby efficient way of building an array from an array of arrays

    - by randombits
    I have an array of ActiveRecord objects, each one which has its own respective errors array. I want to flatten it all out and get only the unique values into one array. So the top level array might look like: foo0 = Foo.new foo1 = Foo.new foo2 = Foo.new foo3 = Foo.new arr = [foo0, foo1, foo2, foo3] Each one of those objects could potentially have an array of errors, and I'd like to get just the unique message out of them and put them in another array, say called error_arr. How would you do it the "Ruby" way?

    Read the article

  • Some questions about setting up Amazon S3 with Ruby on Rails

    - by ben
    I'm trying to setup Amazon S3 hosting with my Ruby on Rails 3 app, which is hosted on Heroku. After reading these instructions in the Heroku docs, I'm trying to use the aws-s3 gem. The instructions say to put the S3 account details in config/amazon_s3.yml, but the aws-s3 Github page says you create a connection like this: AWS::S3::Base.establish_connection!( :access_key_id => 'abc', :secret_access_key => '123' ) Why is the connection created by providing the details if they're already provided in the config file? Is that not the correct way to establish a connection? Do I have to establish a connection for each user everytime an upload is about to occur, or is a connection established for the application as a whole? Thanks for reading.

    Read the article

  • ruby tests - error messages don't include line numbers or file name

    - by joshs
    Hi all, How do I get line numbers to be reported with my errors when testing. Here is what I get back on a typical error: josh@josh-laptop:~/d/test$ ruby unit/line_test.rb -n test_update Loaded suite unit/line_test Started E Finished in 0.066663 seconds. 1) Error: test_update(LineTest): NameError: undefined local variable or method `sdf' for #<LineTest:0xb6e61304> 1 tests, 0 assertions, 0 failures, 1 errors It is tough to debug without a line number and filename. From the code samples I've seen, people generally get back a more verbose error reports. How do I enable this? Thanks!

    Read the article

  • ruby / rails boolean method naming conventions

    - by Dennis
    I have a short question on ruby / rails method naming conventions or good practice. Consider the following methods: # some methods performing some sort of 'action' def action; end def action!; end # some methods checking if performing 'action' is permitted def action?; end def can_action?; end def action_allowed?; end So I wonder, which of the three ampersand-methods would be the "best" way to ask for permissions. I would go with the first one somehow, but in some cases I think this might be confused with meaning has_performed_action?. So the second approach might make that clearer but is also a bit more verbose. The third one is actually just for completeness. I don't really like that one. So are there any commonly agreed-on good practices for that?

    Read the article

  • locale based sorting function in ruby

    - by railscoder
    For my application(Ruby on Rails) i have country select box for the signup page. These countries are localized into different language. But i couldnt find a way to sort them, based on the language in which its localized. At present i have sorted it out based on english only. Is there a way to sort the country names based on the locale? i.e the order of the countries should change(ascending order) according to the language its localised. Thanks..

    Read the article

  • ruby on rails: audio/mp3 content header download

    - by bandhunt
    How do you set the headers for downloads in ruby/rails? In php I'd set the header for an mp3 download like this: header("Content-Transfer-Encoding: binary"); header("Content-type: audio/mp3"); header("Content-Disposition: attachment; filename=\"$songname.mp3\""); header("Content-Length: " . $size); @readfile("http://example.com/12345.mp3"); Seems like there should be an easy should an easy solution. I did find this: response.headers['Content-type'] = 'Content-type: audio/mp3' But I'm not sure how/where the readfile would come into play and other headers. Thanks!

    Read the article

  • Escape doube and single backslashes in a string in Ruby

    - by Nick Gorbikoff
    Hello. I'm trying to access a network path in my ruby script on a windows platform in a format like this. \\servername\some windows share\folder 1\folder2\ Now If I try to use this as a path, it won't work. Single backslashes are not properly escaped for this script. path = "\\servername\some windows share\folder 1\folder2\" d = Dir.new(path) I tried everything I could think of to properly escape slashes in the path. However I can't escape that single backslash - because of it's special meaning. I tried single quotes, double quotes, escaping backslash itself, using alternate quotes such as %Q{} or %q{}, using ascii to char conversion. Nothing works in a sense that I'm not doing it right. :-) Right now the temp solution is to Map a network drive N:\ pointing to that path and access it that way, but that not a solution. Does anyone have any idea how to properly escape single backslashes? Thank you

    Read the article

  • Breakdown of this Ruby code?

    - by randombits
    Would anyone be kind enough to dissect the merge! method? Its usage of conditions and variable assignment looks rather terse, and I'm having a difficult time following it. Would love to hear a Ruby-savvy developer break this apart. module ActiveRecord class Errors def merge!(errors, options={}) fields_to_merge = if only=options[:only] only elsif except=options[:except] except = [except] unless except.is_a?(Array) except.map!(&:to_sym) errors.entries.map(&:first).select do |field| !except.include?(field.to_sym) end else errors.entries.map(&:first) end fields_to_merge = [fields_to_merge] unless fields_to_merge.is_a?(Array) fields_to_merge.map!(&:to_sym) errors.entries.each do |field, msg| add field, msg if fields_to_merge.include?(field.to_sym) end end end end

    Read the article

  • ruby on rails regular expression to remove html tags and its content from text

    - by salilgaikwad
    Hi All, I want regular expression in ruby on rails which remove all the html tags and its content from the given text. For example if my text is :-INPUT :- <span id="span_is"><br><br><u><i>Hi</i></u></span> then it should display only OUTPUT should be as follows:- Hi in short i want regular expression or a function which remove < and whatever the content between <. Thanks & Regards, Salil Gaikwad

    Read the article

  • Installing Ruby on Rails in Fresh Ubuntu 10.10 System

    - by Benedict Aluan
    There are a lot of tutorials on how to install Ruby on Rails in Ubuntu 10.10. But even following the steps, there are still errors and dependencies that will encountered in order to successfully install RoR. The system varies on the developer's setup. To make it uniform, installation must be on a fresh Ubuntu 10.10 system. Is there a step-by-step guide on how to install RoR on a Fresh Ubuntu 10.10 machine? Like the first thing I need to do after starting the terminal.

    Read the article

  • Regular expression in Ruby

    - by Sainath Mallidi
    Hi, Could anybody help me make a proper regular expression from a bunch of text in Ruby. I tried a lot but I don't know how to handle variable length titles. The string will be of format <sometext>title:"<actual_title>"<sometext>. I want to extract actual_title from this string. I tried /title:"."/ but it doesnt find any matches as it expects a closing quotation after one variable from opening quotation. I couldn't figure how to make it check for variable length of string. Any help is appreciated. Thanks.

    Read the article

  • Ruby/RoR: calling original method via super()?

    - by fearless_fool
    In a RoR app, I want to specialize ActiveRecord's update_attributes() method in one of my models, extracting some of the attributes for special handling and passing the rest of them to the original update_attributes() method. The details: class Premise < ActiveRecord::Base ... def update_attributes(attrs) attrs.each_pair do |key, val| unless has_attribute?(key) do_special_processing(key, val) attrs.delete(key) end end # use original update_attributes() to process non-special pairs super.update_attributes(attrs) end ... end The call to super.update_attributes(attr) raises an error: undefined method `update_attributes' for true:TrueClass ... which makes me suspect I really don't understand the super keyword in Ruby. What am I missing? Specifically, how do I call the original update_attributes() method?

    Read the article

  • Solr Vs. Sphinx in a Ruby project

    - by Robert Ross
    I have a project that is being written on top of the Grape API framework in ruby. (https://github.com/intridea/grape) The problem I'm having is that Thinking-Sphinx vs. Sunspot (Gems used to interface with each search index) have worlds different benchmarks. View the Benchmark Here We're trying to develop something that is quick and easy to deploy (Solr needs Java). The issues we see right now is mainly that Solr is slower through Sunspot gem and Sphinx is faster through Thinking-Sphinx because Solr is HTTP REST calls where Sphinx is sockets. Anyone have any experience in either and can explain pitfalls / bonuses? Note: Needs to be deployable to Rails AND non-rails apps (Hence Sunspot). Thanks!

    Read the article

  • Overriding Ruby's spaceship operator <=>

    - by ericsteen1
    I am trying to override Ruby's <= (spaceship) operator to sort apples and oranges so that apples come first sorted by weight, and oranges second, sorted by sweetness. Like so: module Fruity attr_accessor :weight, :sweetness def <=>(other) # use Array#<=> to compare the attributes [self.weight, self.sweetness] <=> [other.weight, other.sweetness] end include Comparable end class Apple include Fruity def initialize(w) self.weight = w end end class Orange include Fruity def initialize(s) self.sweetness = s end end fruits = [Apple.new(2),Orange.new(4),Apple.new(6),Orange.new(9),Apple.new(1),Orange.new(22)] p fruits #should work? p fruits.sort But this does not work, can someone tell what I am doing wrong here, or a better way to do this?

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >