Search Results

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

Page 136/378 | < Previous Page | 132 133 134 135 136 137 138 139 140 141 142 143  | Next Page >

  • Ruby on Rails: How best to escape a string in a model?

    - by williamjones
    I want my application to sanitize html on input rather than on display, so that the fields saved into the database are sanitized. I've been doing this with strip_tags, and it was working great. However, this has the downside that it means the user can't input anything that's bracketed with < and . How can I tell Rails in the model to securely escape tags before saving them to the database? I'd like to not have to call h on the sanitized fields again before using them in the views.

    Read the article

  • Ruby on Rails: building a model with an attribute not in the database?

    - by randombits
    I have a model that sets one of its attributes based off of a form parameter that a user submits. The model is a child resource to a parent resource Home. A hypothetical example is the following: A class Person has an age attribute. The user submits a birthdate as an HTTP POST parameter and from that, I need to derive the age of the user. So I'd do something like this: @home.people.build(:name => params[:name], :birthdate => params[:birthdate]) Rails would barf on that for obvious reasons, complaining it doesn't know what the attribute birthdate is. What's the proper way of going about this? Is it possible to use the build constructor with the supplied solution so that my foreign key relations are also setup properly? If not, what's a better way to work around this problem?

    Read the article

  • Using Ruby on Rails, can a polymorphic database be created in a few steps (with polymorphic associat

    - by Jian Lin
    I thought it could be created in a few steps but it can't yet: rails poly cd poly ruby script/generate scaffold animal name:string obj_type:string obj_id:integer rake:migrate ruby script/generate scaffold human name:string passportNumber:string rake:migrate ruby script/generate scaffold dog name:string registrationNumber:string rake:migrate and now change app/models/animal.rb to: class Animal < ActiveRecord::Base belongs_to :obj, :polymorphic => true end and run ruby script/server and go to http://localhost:3000 I thought on the server then if I create an Michael, Human, J123456 and then Woofie, Dog, L23456 then the database will have entries in the Dogs table and "Humen" or "Humans" table as well as in the Animals table? But only the Animals table has records, Dogs and "Humen" do not for some reason. Is there some steps missing?

    Read the article

  • Rails Metaprogramming: How to add instance methods at runtime?

    - by Larry K
    I'm defining my own AR class in Rails that will include dynamically created instance methods for user fields 0-9. The user fields are not stored in the db directly, they'll be serialized together since they'll be used infrequently. Is the following the best way to do this? Alternatives? Where should the start up code for adding the methods be called from? class Info < ActiveRecord::Base end # called from an init file to add the instance methods parts = [] (0..9).each do |i| parts.push "def user_field_#{i}" # def user_field_0 parts.push "get_user_fields && @user_fields[#{i}]" parts.push "end" end Info.class_eval parts.join

    Read the article

  • Rails/SQl query help: Find all by created_at in past 7 days per each day?

    - by Senthil
    I'm unable to get SQL and Rails to play properly when trying to find Categories that are created each day, the past 7 days. So basically I want to find each Category sorted by the day they were created for the past 7 days. I found this on stackoverflow, but it isn't finding a Category that I just created: Category.all(:conditions => ["created_at > ? AND created_at < ?", t.at_beginning_of_day, t.tomorrow.at_beginning_of_day]) Any help?

    Read the article

  • how do i set up a load balanced Rails web server using mongrel, lighttpd and iis on windows 2003

    - by user91519
    I understand that this is not the perfect environment for doing this but please stick with me and help if you can... The set up I want to achieve is to have my rails application running on a windows 2003 server, using a pack of mongrels with lighttpd acting as the load balancer and IIS in front of it all passing client requests to lighttpd. first of all i've followed these instructions: deploying to iis on windows And I've managed to get the application to run, BUT if the client clicks on a link button the app bombs out with a 500 server error. If I just run against one of the mongrel servers, the the app behaves ok, so I think its lightpd. Its almost as if the lighttpd gets confused with multiple GET requests (i.e. multiple clicks) and bombs out. Any help on why i'm getting 500 errors would be helpful, thanks.

    Read the article

  • Why is it supposedly "hard" to deploy Ruby on Rails to production?

    - by johnny
    I admit that I don't follow much of anything "right" on deploying test versus production code. I have been using ASP.NET, and I typically run it locally in Visual Studio, it works, I upload it, I test it again on the production server. I have read several people say that deploying Rails apps is harder and there are special programs/ways on the ruby site about deploying RoR. I've only toyed with RoR. What is special about deployment? You don't just copy and paste the code and run it (from development machine to the production)? Is it because one is in Apache and the other running on the built in server? This will be on a Mac Server if it matters. Thank you for comments.

    Read the article

  • Googlebot substitutes the links of Rails app with subdomain.

    - by Victor
    I have this Rails app, with domain name abc.com. I am also having a separate subdomain for Piwik stats, in this subdomain stats.abc.com. Googlebot somehow listed some of the links with my subdomain too. http://abc.com/login http://stats.abc.com/login http://abc.com/signup http://stats.abc.com/signup The ones with stats will reference to the same page in the app, but are treated entirely different website. I have put in robots.txt in stats after this matter, but wondering if there is any appropriate way to block this because I may have new subdomains in future. Here's my content in robots.txt User-agent: * Disallow: / Thanks.

    Read the article

  • How do I load content with ujs, jquery and rails?

    - by Joseph Silvashy
    I'm trying to figure out the best way to insert content into a light box using rails UJS. I have a link that looks like this: <%= link_to "login", login_path, :remote => true %> Which produces html as such: <a data-remote="true" href="/login">login</a> So this all works great, and I've created the view file: user_sessions/new.js.erb which also loads just fine, but my question what is the preferred method of inserting appending the html into the page? Like I already have the login form on the non-js page, so can't I just load that partial into the page? Any ideas would be very welcomed.

    Read the article

  • How can I make the Rails 3 router localize URLs using localization files?

    - by edgerunner
    What I'd like to be able to do is: in config/routes.rb resources :posts in config/locale/en.yml en: resources: posts: "posts" new: "new" edit: "edit" in config/locale/tr.yml tr: resources: posts: "yazilar" new: "yeni" edit: "duzenle" and get I18n.locale = :en edit_post_path(3) #=> /posts/3/edit I18n.locale = :tr edit_post_path(3) #=> /yazilar/3/duzenle I'd also like Rails to match any of these routes anytime and pass the associated locale in the params hash such that when I navigate to /yazilar , the request should be routed to the posts#index action with the :tr locale in the params hash. Any simple or complex way of doing that?

    Read the article

  • Rails setting OR conditions in validate_presence_of in a model?

    - by Jty.tan
    In a rails model, is it possible to do something like class Example < ActiveRecord::Base #associations validates_presence_of :item_id, (:user_id OR :user_email) #functions end Where the model has 3 columns of :item_id, :user_id, and :user_email? I want the model to be valid as long as I have a :user_id or a :user_email. Idea being that if the item is recommended to a person who isn't currently signed up, it can be associated via email address for when the recommended person signs up. Or is there a different method that I can use instead?

    Read the article

  • Rails 3 routes and using GET to create clean URLs?

    - by Hard-Boiled Wonderland
    I am a little confused with the routes in Rails 3 as I am just starting to learn the language. I have a form generated here: <%= form_tag towns_path, :method => "get" do %> <%= label_tag :name, "Search for:" %> <%= text_field_tag :name, params[:name] %> <%= submit_tag "Search" %> <% end %> Then in my routes: get "towns/autocomplete_town_name" get "home/autocomplete_town_name" match 'towns' => 'towns#index' match 'towns/:name' => 'towns#index' resources :towns, :module => "town" resources :businesses, :module => "business" root :to => "home#index" So why when submitting the form do I get the URL: /towns?utf8=?&name=townname&commit=Search So the question is how do I make that url into a clean url like: /towns/townname Thanks, Andrew

    Read the article

  • Is Amazon SQS the right choice here? Rails performance issue.

    - by ole_berlin
    I'm close to releasing a rails app with the common networking features (messaging, wall, etc.). I want to use some kind of background processing (most likely Bj) for off-loading tasks from the request/response cycle. This would happen when users invite friends via email to join and for email notifications. I'm not sure if I should just drop these invites and notifications in my Database, using a model and then just process it with a worker process every x minutes or if I should go for Amazon SQS, storing the messages and invites there and let my worker retrieve it from Amazon SQS for processing (sending the invites / notifications). The Amazon approach would get load off my Database but I guess it is slower to retrieve messages from there. What do you think?

    Read the article

  • Rails/SQl query help: Find all created Categories past 7 days per each day?

    - by Senthil
    I'm unable to get SQL and Rails to play properly when trying to find Categories that are created each day, the past 7 days. So basically I want to find each Category sorted by the day they were created for the past 7 days. I found this on stackoverflow, but it isn't finding a Category that I just created: Category.all(:conditions => ["created_at > ? AND created_at < ?", t.at_beginning_of_day, t.tomorrow.at_beginning_of_day]) Any help?

    Read the article

  • Does it make sense to use BOTH mongodb and mysql in the same rails application?

    - by Brian Armstrong
    I have a good reason to use mongodb for part of my app. But people generally describe it as not a good fit for "transactional" applications like a bank where transactions have to be exact/consistent, etc. Does it make sense to split the models up in Rails and have some of them use MySql and others mongo? Or will this generally cause more problems than it's worth? I'm not building a banking app or anything, but was thinking it might make sense for my users table or or transactions table (recording revenue) to do that part in MySql.

    Read the article

  • What would you use for auto completion in Rails app?

    - by Andrei
    I want to use auto-completion in a number of fields (5-7) in my forms. There is a screencast on auto-completion with Prototype library by Ryan Bates ( http://railscasts.com/episodes/102-auto-complete-association). On the other hand, I have noticed that quite many guys suggest jQuery for this task ( http://jquery.bassistance.de/autocomplete/demo/). And I guess, there was probably some development last year(s), so I ask you - what would you use nowadays to auto-complete your form fields and why? BTW, I still have an open question on auto completion for HABTM association: http://stackoverflow.com/questions/1510935/how-to-do-habtm-management-with-auto-completion-in-rails

    Read the article

  • How can I change the link format in will_paginate for page_cache in Ruby on Rails?

    - by jaehyun
    I want to use page_cache with will_paginate. There are good information on this page below. http://railsenvy.com/2007/2/28/rails-caching-tutorial#pagination http://railslab.newrelic.com/2009/02/05/episode-5-advanced-page-caching I wrote routes.rb looks like: map.connect '/products/page/:page', :controller => 'products', :action => 'index' But, links of url are not changed to '/products/page/:page' which are in will_paginate helper. They are still 'products?page=2' How can i change url format is in will_paginate?

    Read the article

  • Ruby on Rails: one-to-one mapping. Just semantics or really a different structure.

    - by Sam
    So I'm creating a plugin for Ruby on Rails to make implemented addresses including country, state, city, and zip_code for countries that can follow that paradigm a lot easier but that's beside the point expect for how the address model is associated. So starting with my address model. class Address < ActiveRecord::Base has_one :country has_one :state has_one :city has_one :zip_code end What's the difference between saying belongs_to and has_one Seems to be the same thing because both only require one model to declare ownership and foreign_key And it also seems that both are logical to say. an address belongs to an account and an account has one address Is this only semantics or is there are real difference

    Read the article

  • How do you crop a specific area with paperclip in Rails (3)?

    - by Smickie
    Hi, I have paperclip in Rails (3) working with simple cropping, for example the blow code makes a simple crop of the thumbnail: has_attached_file :image, :styles => { :thumb => "90x90#" }, :default_style => :thumb However I was wondering how do you crop a very specific area of an image; lets say you have an x and y coordinate to start from and then a width and height of the crop. How do you go about passing a complex style like this in? Thanks very much.

    Read the article

  • Rails: find_by_sql and PREPARE stmt FROM... i cant make it work

    - by Totty
    I have this query and I have an error: images = Image.find_by_sql('PREPARE stmt FROM \' SELECT * FROM images AS i WHERE i.on_id = 1 AND i.on_type = "profile" ORDER BY i.updated_at LIMIT ?, 6\ '; SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit;') Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit' at line 1: PREPARE stmt FROM ' SELECT * FROM images AS i WHERE i.on_id = 1 AND i.on_type = "profile" ORDER BY i.updated_at LIMIT ?, 6'; SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit; EDIT: after finding the answer to: http://stackoverflow.com/questions/2566620/mysql-i-need-to-get-the-offset-of-a-item-in-a-query i need another help here to port it to rails.

    Read the article

  • Possible to see what actual SQL queries Rails invokes when using console script?

    - by randombits
    Sometimes I like to pop open the console script that comes with Rails to test small excerpts of code. That code normally involves some more involved ActiveRecord queries. Although not an expert in ActiveRecord, I'm proficient with SQL and want to see what it's translating underneath the hood for efficiency purposes. This will help me refactor or rethink how I'm writing my app if it looks inefficient. Now when the query is in the actual application itself, it all shows up in logs. Ad-hoc ActiveRecord queries in the console do not though. Anyway to change that behavior?

    Read the article

  • Why is rails setting ":null => false" on all my columns in schema.rb?

    - by ryeguy
    Even if I never specify :null => false in my migrations that initially add columns to tables, rails still generates code in schema.rb that specifies the columns as having :null => false. Why is this? If I develop on my box, and then use rake db:schema:load on my production box, I'm going to get very different behavior! Edit: Even if I delete schema.rb and run rake db:schema:dump, it still puts :null => false on the new schema even if it isn't defined like that in the actual database. It seems it can't tell whether or not a column is marked as allowing nulls. I'm using SQLite if that helps.

    Read the article

  • Attach 1 or more (non image) files to rails application, with having to install an image-processing

    - by Hinchy
    Hi all, I'm currently learning rails by creating a simple project management app. I've gotten to the point where I would like to be allow a user upload multiple files - pdfs, docs, xls etc. The user only needs to be able to attach one file at a time, but the possibilty to have multiple documents associated with a project is a must. I've spent quite a lot of time researching my options, and it appears the two main plugins are attachment_fu and paperclip. From what I've read though, these appear to concentrate specifically on the upload and subsequent resizing of images, something I couldn't care less about. Is there a simpler way to achieve what I'm trying? Thank you all in advance.

    Read the article

  • Using Rails and Rspec, how do you test that the database is not touched by a method

    - by Will Tomlins
    So I'm writing a test for a method which for performance reasons should achieve what it needs to achieve without using SQL queries. I'm thinking all I need to know is what to stub: describe SomeModel do describe 'a_getter_method' do it 'should not touch the database' do thing = SomeModel.create something_inside_rails.should_not_receive(:a_method_querying_the_database) thing.a_getter_method end end end EDIT: to provide a more specific example: class Publication << ActiveRecord::Base end class Book << Publication end class Magazine << Publication end class Student << ActiveRecord::Base has_many :publications def publications_of_type(type) #this is the method I am trying to test. #The test should show that when I do the following, the database is queried. self.publications.find_all_by_type(type) end end describe Student do describe "publications_of_type" do it 'should not touch the database' do Student.create() student = Student.first(:include => :publications) #the publications relationship is already loaded, so no need to touch the DB lambda { student.publications_of_type(:magazine) }.should_not touch_the_database end end end So the test should fail in this example, because the rails 'find_all_by' method relies on SQL.

    Read the article

  • Which type of Rails model association should I use in this situation?

    - by jstayton
    I have two models/tables in my Rails application: discussions and comments. Each discussion has_many comments, and each comment belongs_to a discussion. My discussions table also includes a first_comment_id column and last_comment_id column for convenience and speed. I want to be able to call discussion.last_comment for the last comment model, but the following (in my discussion model) isn't working to make this happen: has_one :first_comment, :class_name => "Comment" has_one :last_comment, :class_name => "Comment" When I call discussion.last_comment, the following SQL is run: SELECT * FROM `comments` WHERE (`comments`.discussion_id = 1) LIMIT 1 It's using the discussions.id column to join against comments.discussion_id, when I want it to join discussions.last_comment_id against comments.id. Am I using the wrong type of association here? Thanks for your help!

    Read the article

< Previous Page | 132 133 134 135 136 137 138 139 140 141 142 143  | Next Page >