Search Results

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

Page 74/378 | < Previous Page | 70 71 72 73 74 75 76 77 78 79 80 81  | Next Page >

  • Rails 3 find all associated records has_many :through

    - by Sergey
    I would like to list all posts that are connected with some specific category. I have: class Post < ActiveRecord::Base has_many :category_posts has_many :categories, :through => :category_posts end class Category < ActiveRecord::Base has_many :category_posts has_many :posts, :through => :category_posts end class CategoryPost < ActiveRecord::Base belongs_to :category belongs_to :post end And I wanna do something like this Post.where(["category.id = ?", params[:category_id]]) It indeed is very simple task, but I don't know what I should be looking for (keywords). It's the same problem like this, but in rails.

    Read the article

  • Loading non-RJS javascript via ajax in Rails

    - by David Smith
    I've written a rails module that generates some javascript for a google map. As the user makes changes on the webpage, I use observe_field to call back to the server to regenerate the map's javascript (without updating the whole page). I'm having trouble finding a good way to insert the new javascript into the page. I've tried <div id='my_div_1'>div1</div> <%= update_page_tag do |page| page.replace_html 'my_div_1', "<script>alert('hi');</script>" end %> but it seems that replace_html only works for non-script html. It chokes when the content includes the closing < /script tag. Additional information...here is a page that I think is the root of the problem. http://www.wwco.com/~wls/blog/2007/04/25/using-script-in-a-javascript-literal/

    Read the article

  • How to handle this type of model validation in Ruby on Rails

    - by randombits
    I have a controller/model hypothetically named Pets. Pets has the following declarations: :belongs_to owner :has_many dogs :has_many cats Not the best example, but again, it demonstrates what I'm trying to solve. Now when a request comes in as an HTTP POST to http://127.0.0.1/pets, I want to create an instance of Pets. The restriction here is, if the user doesn't submit at least one dog or one cat, it should fail validation. It can have both, but it can't be missing both. How does one handle this in Ruby on Rails? Dogs don't care if cats exists and the inverse is also true. Can anyone show some example code of what the Pets model would look like to ensure that one or the other exists, or fail otherwise? errors.add also takes an attribute, in this case, there is no particular attribute that's failing. It's almost a 'virtual' combination that's missing.

    Read the article

  • MySQL driver for Rails in Windows 7 x64

    - by Darth
    I've got problem with connecting to MySQL database on my freshly installed Windows 7 machine. I'm getting this error when I try to migrate my database. !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql. rake aborted! 193: %1 is not valid Win32 application - C:/Ruby/lib/ruby/gems/1.8/gems/mysql-2.8.1-x86-mswin32/lib/1.8/mysql_api.so I currently have installed ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] mysql version 5.0.86 for Win64 gem 1.3.1 mysql-2.8.1-x86-mswin32

    Read the article

  • View code inside Javascript file on Rails

    - by SpyrosP
    Hello, previously i had javascript code right in the top of my view and it would work. Then, i learned that you can include the js file using yield and i did just that. I had rails view code inside my javascript code like : $( "#exp-progressbar" ).progressbar({ value: <%= ((@quest.end_time - Time.now).to_i * 100 ) / (@quest.duration * 60) %> }); Now, after i do it with yield, i get an error when i do that in the separate js file. How can i do it now ?

    Read the article

  • Rails: Routing to a different controller based on request format

    - by Jimmy Cuadra
    I'm writing an app where I want all requests for HTML to be handled by the same controller action. I have some other routes that are JSON-specific. Here's what my routes look like: Blog::Application.routes.draw do constraints format: :json do resources :posts end match "(*path)" => "web#index" end The problem is that constraints is being interpreted as "this route only works with the specified format" rather than "skip this route and try the next one if the request is not in the specified format." In other words, navigating to /posts in the browser gives me a 406 Not Acceptable because the URL is constrained to the JSON format. Instead, I want it to fall through to web#index if the request is for HTML, and hit the resourceful route if the request is for JSON. How can this be achieved? (Using Rails 3.2.9.)

    Read the article

  • Rails 3.2.3 mysql error "max_prepared_stmt_count"

    - by Rob Momary
    I am running a Rails 3.2.3 app deployed with apache2/passenger on a virtual host with a mysql database server. I got this error after a lot of traffic was hitting the site: ActiveRecord::StatementInvalid (Mysql::Error: Can't create more than max_prepared_stmt_count statements (current value: 16382) I'm thinking it has something to do with the amount of traffic, but if so I have to find a way around this. Anyone had this error before? I can't figure out how to stop it. Here's what i see in mysql: mysql show global status like 'com_stmt%'; | Com_stmt_close | 1720319 | Com_stmt_execute | 2094137 | | Com_stmt_fetch | 0 | | Com_stmt_prepare | 1768924 | | Com_stmt_reprepare | 0 | | Com_stmt_reset | 0 | | Com_stmt_send_long_data | 0 | +-------------------------+---------+ I am running resque gem.

    Read the article

  • Getting started with Rails testing

    - by yuval
    I asked a question about different testing frameworks yesterday. This question can be found here. Now that I have a better understanding of the different frameworks, I have a very simple question: With a basic understanding, but very limited experience with writing tests with rails' built in testing framework (basic assertions), would it be okay for me to jump directly to testing with RSpec, Webrat, and Cucamber? Thank you! As a side note: yes, this is an opinion based question, but I feel that the input received to this question is valuable enough to the community to keep this question open. Thanks.

    Read the article

  • Rails + facebox + authlogic - how?

    - by Vitaly
    Hello, on my web site I want to have login/registration form in modal window done using facebox (jQuery plugin). What is better: Create view with one method and template that has form and refer facebox to this view. Create static HTML file in public directory and refer facebox to this static page. What I want to achieve is: Easy verification (like "user name already taken", "password confirmation doesn't match password" and stuff like that). Easy submit and redirect I'm new to Rails, I just know about forms verification in Django, so for Django I would probably choose option 1, but it might be another thing in Ruby.

    Read the article

  • jquery $.ajax not working in firefox against rails (406 response) (works in chrome & IE)

    - by phil swenson
    I have a rails backend and am testing the following jquery code against it: var content = $("#notification_content").val(); var data = new Object(); data.content = content; $.ajax({ url: "/notifications/detect_type.json", type:"POST", data: data, success: function(result ){updateTypeDropDown(result)}}); This code works fine in Chrome and IE. However in Firefox (using Firebug), I see this: http://localhost:3000/notifications/detect_type.json 406 Not Acceptable here is a chrome request in the log: Processing NotificationsController#detect_type (for 127.0.0.1 at 2010-12-21 17:05:59) [POST] Parameters: {"action"="detect_type", "content"="226 south emerson denver co 80209", "controller"="notifications"} User Columns (2.0ms) SHOW FIELDS FROM users User Load (37.4ms) SELECT * FROM users WHERE (users.id = '1') LIMIT 1 Completed in 58ms (View: 1, DB: 40) | 406 Not Acceptable [http://localhost/notifications/detect_type.json] here is a firefox request in the log: Processing NotificationsController#detect_type (for 127.0.0.1 at 2010-12-21 17:06:41) [POST] Parameters: {"action"="detect_type", "content"="226 south emerson 80209", "controller"="notifications"} User Columns (2.1ms) SHOW FIELDS FROM users User Load (30.4ms) SELECT * FROM users WHERE (users.id = '1') LIMIT 1 Completed in 100ms (View: 1, DB: 33) | 200 OK [http://localhost/notifications/detect_type.json] I'm stumped. Ideas?

    Read the article

  • rails controller defaults to respond with application/xml in production

    - by Dave Paroulek
    I have a standard contacts_controller.rb with index action that responds as follows: respond_to do |format| format.html format.xml { render :xml => @contacts } end In development, it works as intended: when I browse to http://localhost:3000/contacts, I get an html response. But, when I start the app using capistrano on a remote Ubuntu server and browse to the same url, I get an xml response. If I go to http://remote_host:8000/contacts.html, then I see the html response. If I comment out the format.xml { render :xml => @contacts }, then I see the desired html response. Pretty sure I'm missing something subtle about difference between Rails development and production modes. Any ideas about what I'm overlooking? Thanks, - Dave

    Read the article

  • Ruby On Rails : db:migrate do not run

    - by user332219
    Hi, When i run this command i have an error : rake db:migrate --trace rake aborted! NoMethodError: undefined method `ord' for 0:Fixnum: SET NAMES 'utf8' see the log file here : http://patxi.mayol.free.fr/public/trace.txt my database.yml file is here : MySQL. Versions 4.1 and 5.0 are recommended. # development: adapter: mysql encoding: utf8 reconnect: false database: annuaire_development pool: 5 username: root password: host: 127.0.0.1 test: adapter: mysql encoding: utf8 reconnect: false database: annuaire_test pool: 5 username: root password: host: 127.0.0.1 production: adapter: mysql encoding: utf8 reconnect: false database: annuaire_production pool: 5 username: root password: host: 127.0.0.1 Thanks My config : WampServer 2.0 with MySQL 5.0.51a Aptana 2.0.4 Ruby 1.8.5 Gems: actionmailer (2.3.4, 2.3.2) actionpack (2.3.4, 2.3.2) activerecord (2.3.4, 2.3.2) activeresource (2.3.4, 2.3.2) activesupport (2.3.4, 2.3.2) cgi_multipart_eof_fix (2.5.0) fastthread (1.0.1) gem_plugin (0.2.3) linecache (0.43) mongrel (1.1.5) mysql (2.8.1, 2.7.3) rack (1.0.0) rails (2.3.4, 2.3.2) rake (0.8.7) ruby-debug-base (0.10.3) ruby-debug-ide (0.4.5) sqlite3-ruby (1.2.1)

    Read the article

  • Rails architecture questions

    - by justinbach
    I'm building a Rails site that, among other things, allows users to build their own recipe repository. Recipes are entered either manually or via a link to another site (think epicurious, cooks.com, etc). I'm writing scripts that will scrape a recipe from these sites given a link from a user, and so far (legal issues notwithstanding) that part isn't giving me any trouble. However, I'm not sure where to put the code that I'm writing for these scraper scripts. My first thought was to put it in the recipes model, but it seems a bit too involved to go there; would a library or a helper be more appropriate? Also, as I mentioned, I'm building several different scrapers for different food websites. It seems to me that the elegant way to do this would be to define an interface (or abstract base class) that determines a set of methods for constructing a recipe object given a link, but I'm not sure what the best approach would be here, either. How might I build out these OO relationships, and where should the code go?

    Read the article

  • Dynamic path in new.AjaxRequest with Rails

    - by Robbie
    Hello, I was wondering if there's anyway to get a 'dynamic path' into a .js file through Ruby on Rails. For example, I have the following: new Ajax.Request('/tokens/destroy/' + GRID_ID, {asynchronous:true, evalScripts:true, onComplete:function(request){load('26', 'table1', request.responseText)}, parameters:'token=' + dsrc.id + '&authenticity_token=' + encodeURIComponent(AUTH_TOKEN)}) The main URL is '/tokens/destroy/:id', however on my production server this app runs as a sub folder. So the URL for this ajax call needs to be '/qrpsdrail/tokens/destroy/:id' The URL this is being called from would be /grids/1 or /qrpsdrail/grids/1 I could, of course, do ../../path -- but that seems a bit hackish. It is also dependent on the routing never changing, which at this stage I can't guarantee. I'm just interested in seeing what other solutions there might be to this problem. Thanks in advance :)

    Read the article

  • Rails select list reverts to top?

    - by Danny McClelland
    Hi Everyone, I have number of select lists in my rails application like this: <li>Company<span><%= f.select :company_id, Company.all.collect {|m| [m.companyname, m.id]} %></span></li> They all work well, except - sometimes if you go to the edit view, the select list reverts to the top item, not the item that was chosen when creating. So if you go to an edit view and then click update without actually making any changes, the lists default to the top item - even though you didn't touch them. Is there a way around this? Thanks, Danny

    Read the article

  • Checking if a boolean column is true in MySQL/Rails

    - by Pygmalion
    Rails and MySQL: I have a table with several boolean columns representing tags. I want to find all the rows for which a specific one of these columns is 'true' (or I guess in the case of MySQL, '1'). I have the following code in my view. @tag = params[:tag] @supplies = Supply.find(:all, :conditions=>["? IS NOT NULL and ? !=''", @tag, @tag], :order=>'name') The @tag is being passed in from the url. Why is it then that I am instead getting all of my @supplies (i.e. every row) rather than just those that are true for the column for @tag. Thanks!

    Read the article

  • Write XML File from a flex application back to a rails Server

    - by Markus
    Hi everybody, I have a XML-file, which I want to send to a rails server. To do so I use the following code: <mx:HTTPService id="dataService" result="resultHandler(event)" resultFormat="e4x"/> In a Function triggered by a save button, I do the following: var params:Object = {}; params["xml_file"] = xmlDoc; dataService.method = "POST"; dataService.url = "http://localhost:3000/containers"; dataService.send(params); Unfortunately there is always the Problem (see below) appearing. If I remove the params var, it runs a GET Request... [RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream-Fehler. URL: http://localhost:3000/containers"]. URL: http://localhost:3000/containers"] what could be the problem? Thanks for any hints! Markus

    Read the article

  • Rails Model for Playlist that can contain tracks and albums using polymorphism

    - by philk
    I struggle to find a model how to store a playlist with different type of items on it in Rails. Consider I have class Track end class Album has_many :tracks end class PlaylistItem belongs_to :playable belongs_to :playlist end class Playable belongs_to :playable, :polymorph => true end class Playlist has_many :playlist_items end I think I can use a polymorphic model "Playable" here since the Playlist can contain Tracks, Albums and maybe in the future also Movies. Also I would like to use STI for Track and Albums since they share some common attributes like title and length but also have totally different attributes. I modeled it like described here but it does not work. Anybody any idea how to model a Playlist that can contain many items of different kind?

    Read the article

  • Ruby and Rails Async

    - by Edijs Petersons
    I need to perform long-running operation in ruby/rails asynchronously. Googling around one of the options I find is Sidekiq. class WeeklyReportWorker include Sidekiq::Worker def perform(user, product, year = Time.now.year, week = Date.today.cweek) report = WeeklyReport.build(user, product, year, week) report.save end end # call WeeklyReportWorker.perform_async('user', 'product') Everything works great! But there is a problem. If I keep calling this async method every few seconds, but the actual time heavy operation performs is one minute things won't work. Let me put it in example. 5.times { WeeklyReportWorker.perform_async('user', 'product') } Now my heavy operation will be performed 5 times. Optimally it should have performed only once or twice depending on whether execution of first operaton started before 5th async call was made. Do you have tips how to solve it?

    Read the article

  • link_to_remote in rails, problem pass :id

    - by nakada
    i have problem use link_to_remote link_to_remote document example say link_to_remote "Delete this post", :update => "posts", :url => { :action => "destroy", :id => post.id } this code make below html code <a href="#" onclick="new Ajax.Updater('posts', '/blog/destroy/3', {asynchronous:true, evalScripts:true}); return false;">Delete this post</a> but my app don't. my html is <a href="#" onclick="new Ajax.Updater('posts', '/blog/6', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('2C4Yo8OIDN+dm9oieL37uRg++PuWa8LCz18gW5Cu+Vg=')}); return false;">Delete this post</a> where is destroy in url? i expected '/blog/destroy/6' but actually 'blog/6' what's the problem? my rails version is 2.3.5

    Read the article

  • Rails is not passing the "commit" button parameter

    - by Wayne M
    Reinstalling a Rails app on a new server. Part of the app can fork in one of two directions based on the button the user selects. This part isn't working, and when I look at the log I see the values that I gave the form, execept for the commit portion of the params hash. This seems to be why the app isn't working as expected (since there's nothing in params[:commit], but I have no idea why commit would not be passed in; the request is definitely a POST request, and all of the other parameters are there.

    Read the article

  • Undefined method 'total_entries' after upgrading Rails 2.2.2 to 2.3.5

    - by Trevor
    I am upgrading a Rails application from 2.2.2 to 2.3.5. The only remaining error is when I invoke total_entries for creating a jqgrid. Error: NoMethodError (undefined method `total_entries' for #<Array:0xbbe9ab0>) Code snippet: @route = Route.find( :all, :conditions => "id in (#{params[:id]})" ) { if params[:page].present? then paginate :page => params[:page], :per_page => params[:rows] order_by "#{params[:sidx]} #{params[:sord]}" end } respond_to do |format| format.html # show.html.erb format.xml { render :xml => @route } format.json { render :json => @route } format.jgrid { render :json => @route.to_jqgrid_json( [ :id, :name ], params[:page], params[:rows], @route.total_entries ) } end Any ideas? Thanks!

    Read the article

  • Elegant PostgreSQL Group by for Ruby on Rails / ActiveRecord

    - by digitalfrost
    Trying to retrieve an array of ActiveRecord Objects grouped by date with PostgreSQL. More specifically I'm trying to translate the following MySQL querry: @posts = Post.all(:group => "date(date)", :conditions => ["location_id = ? and published = ?", @location.id, true], :order => "created_at DESC") I am aware that PostgreSQL interpretation of the SQL standard is stricter than MySQL and that consequently this type of query won't work...and have read a number of posts on StackOverflow and elsewhere on the subject - but none of them seem to be the definitive answer on this subject I've tried various combinations of queries with group by and distinct clauses without much joy - and for the moment I have a rather inelegant hack which although works makes me blush when I look at it. What is the proper way to make such a querry with Rails and PostgreSQL ? (Ignoring the fact that surely this should be abstracted away at the ActiveRecord Level)

    Read the article

  • How to secure images with Rails?

    - by NotDan
    I have a gallery in my rails app that needs to only allow certain images to be shown to specific, logged in users. I am using Paperclip for image processing now, but it saves all images in a public folder available to anyone. Note that I don't have to use Paperclip if there is a better way, and I already have the login system in place. I just need a way to place the images in a non-public location, but still be able to serve them as needed. Is it possible to only allow these images to be served to authenticated users?

    Read the article

  • Unrecognized authentication type when doing an Auth to Exchange from Rails

    - by blakeage
    I'm getting this error when trying to authenticate with Exchange Server from Ruby on Rails: 504 5.7.4 Unrecognized authentication type config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_deliveries = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => "x.x.x.x", :port => 25, :user_name => "xxdomain\xxuser", :password => "xxxxxx", :authentication => :login, :enable_starttls_auto => true } I've tried all sorts of combinations of configuration settings, including changing the settings to use "plain" authentication, adding the domain, setting enable_starttls_auto to true, false, and removing it entirely, removing the port. Nothing has worked. Any ideas?

    Read the article

< Previous Page | 70 71 72 73 74 75 76 77 78 79 80 81  | Next Page >